Dynamic Rendering in NextJS
Dynamic Rendering in NextJS
NEXT.JS
Vladyslav Demirov
VLADYSLAV DEMIROV 1
🔍 Understanding Dynamic Rendering:
Dynamic rendering in Next.js allows us to
fetch data at runtime and render pages
on the server or the client side,
depending on the scenario. Let's delve
into a few examples to illustrate this
concept.
VLADYSLAV DEMIROV 3
🔄 Client-Side Rendering (CSR) with
useEffect: If you prefer client-side
rendering, you can fetch data on the
client side using useEffect:
🚀 How It Works:
DynamicPage Component:
- A React component, DynamicPage,
responsible for rendering dynamic
content.
VLADYSLAV DEMIROV 5
- Displays a simple message along with
data fetched at request time.
getServerSideProps Function:
- The magic happens in
getServerSideProps.
- It's an async function that fetches data
based on the dynamic parameter
(params.id) during server-side
rendering.
- The fetched data is passed as props to
the DynamicPage component.
Dynamic Rendering in Action:
- When a user navigates to a dynamic
route (e.g., /dynamic/123), Next.js
fetches the data at the server before
rendering the page.
- This ensures that the page is fully
rendered with the latest data before
being served to the client.
VLADYSLAV DEMIROV 6
🚀 Advantages of Dynamic Rendering in
Next.js:
•SEO Optimization: Server-side
rendering enhances search engine
optimization by providing fully-
rendered pages.
•Dynamic Content: Fetching data at
request time ensures that users see
the most up-to-date information.
•Flexibility: Next.js allows you to
choose the rendering approach that
best suits your application's needs.
VLADYSLAV DEMIROV 7
HAPPY CODING!
VLADYSLAV DEMIROV 8