Skip to content

FlashcardNot attempted

Hydration

Recall it before you reveal

What is hydration, and why must the first client render match the server HTML?

Space to reveal
Show answer & explanation

The server (or the build) sent finished HTML, so the page is visible but not interactive: no event handlers are attached yet. Hydration is React rendering the same tree in the browser and adopting the existing DOM (hydrateRoot) instead of creating it, attaching handlers as it goes.

React assumes the DOM it adopts is what it would have rendered. If the first client render differs (a date, Math.random(), data read from localStorage, typeof window checks), React reports a hydration mismatch and may re-render that part on the client, which costs time and can flash. The usual fix is to render the server's version first and switch to client-only data in an effect or with useSyncExternalStore's server snapshot.