Capítulo 95 de 116
hydrateRoot(domNode, reactNode, options?) attaches React to DOM nodes that were already server-rendered, reusing the existing markup and attaching event listeners rather than tearing down and re-creating the DOM from scratch — the client half of the SSR story.
hydrateRoot(domNode, reactNode, options?) — domNode is the container already holding server-rendered HTML, reactNode is the same JSX tree the server rendered (must match, or hydration mismatches occur).window-only APIs, locale-dependent formatting) without guarding it — a frequent source of hydration warnings.onRecoverableError option: hydration mismatches that React can recover from (by patching the DOM) still fire this callback, letting an app log/monitor them even though the user doesn't see a broken page.createRoot: don't use hydrateRoot on an empty container (nothing to reconcile against) and don't use createRoot on server-rendered markup you want preserved (it would discard and rebuild the DOM instead of reusing it).import { hydrateRoot } from 'react-dom/client';
hydrateRoot(document.getElementById('root'), <App />);
#root, matching it exactly with the same <App /> tree the server used.hydrateRoot specifically when the server already produced the initial HTML — it reuses that DOM instead of rebuilding it.window, locale) is the classic source of hydration mismatches — guard it explicitly (e.g. render a placeholder on first client render, then update after mount).