AceDevHub
Advanced React Interview QuestionsAdvancedComparison

React · Question 86

What is the difference between createRoot and hydrateRoot?

Direct answer

createRoot renders React into a client-owned DOM container, while hydrateRoot attaches React behavior to HTML that was already rendered on the server and is expected to match the client's initial output.

ConcerncreateRoothydrateRoot
Starting DOMContainer is rendered by the client rootContains server-rendered React HTML
Primary purposeClient renderingHydration of server-rendered markup
Markup matching requirementNo server markup contractInitial client output must match server HTML
Typical framework usePure client entrySSR/streamed application entry

Hydration is not simply 'render React again'. React attempts to attach event handling and component behavior to the existing server-generated structure.