Cerulean
Cerulean

Reputation: 6013

When and how are React lifecycle methods called in the NextJS SSR process?

This is a simple question that almost certainly is answered in the NextJS documentation somewhere, but after looking (as well as googling for some writeup about it) I can't find it.

As I understand it, NextJS works thusly:

Part of the issue is that I have zero knowledge of how React works internally -- what relation painting the screen and lifecycle methods have with each other.

I'm trying to understand how NextJS works -- what exactly is the flow, and how NextJS' SSR and React work together, and what happens when and where.

Upvotes: 13

Views: 9354

Answers (1)

leerob
leerob

Reputation: 3122

But does this imply that is there a second render on the client-side after the original SSR, that is, the original HTML delivered is replaced by the SPA?

What you're describing is what's called the "rehydration" process. Next will return the server-side content and then rehydrate on the client-side through effects (e.g., useEffect) or data fetching client-side (e.g., SWR).

I would recommend watching this video for a more detailed explanation from Tim, the lead maintainer of Next.js.

Upvotes: 7

Related Questions