Next.js stands out as a robust framework that facilitates both client and server-side rendering, setting it apart from other React frameworks. With client-side rendering, all code is generated in the client's browser. However, with server-side rendering, pages can be pre-rendered on the server before being sent to the client.
To achieve server-side rendering with Next.js, follow these steps:
So how to achieve this
Step 1: Create an 'actions' folder in your Next.js directory.
Step 2. Populate the actions folder with async functionse.e.g (fetch, Axios)
`export async function Test() {
}
`
Step 3. *Utilize these async functions in your Next.js pages *.
Since Next.js primarily renders pages on the server-side, you'll need to call these functions within your pages to fetch data. Here's an example:
export default async function Dummy() {
const Data = await Test();
console.log(Data);
Following these steps allows you to implement server-side rendering with Next.js, enabling efficient data fetching from APIs.
Feel free to reach out if you have any questions or need further clarification!
Thanks
Top comments (1)
Straight to the point, great!