Skip to content

Hydration

In one line

Hydration turns static server-rendered HTML into a fully interactive React app by attaching event handlers.

In simple words

Hydration is the process where React takes server-rendered HTML and makes it interactive. The server sends HTML (fast first paint), then React runs on the client and "hydrates" that HTML by:

  1. Attaching event listeners — onClick, onChange, etc.
  2. Setting up state — initializing hooks
  3. Building the virtual DOM — matching the server HTML

If the server HTML and client React tree don't match, you get a hydration mismatch warning. React 18 with hydrateRoot supports selective hydration — it can hydrate parts of the page independently, and even hydrate before all HTML is downloaded.

Example

jsx
import { hydrateRoot } from "react-dom/client";
import App from "./App";

// Server sends HTML, client hydrates it
// HTML: <div id="root"><button>Count: 0</button></div>

hydrateRoot(
  document.getElementById("root"),
  <App />
);

// React 18: selective hydration
// Only hydrates what's visible, can pause for user interaction

hydrateRoot attaches React to existing server HTML. React 18 can hydrate selectively and interrupt hydration for urgent user events.

Common confusions

  • Confused with: rendering

    The difference: Rendering creates the initial DOM from React components. Hydration takes existing DOM (from server HTML) and attaches React's event system and state to it. Rendering builds from scratch; hydration connects to what's already there.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary