React Reference ยท react-dom Client APIs
React root.render() method
Reference for root.render(): show a React tree in a root, update it by rendering again, and learn what is batched, preserved or reset between calls.
root.render(reactNode) tells a root what to display. The first call mounts the tree into the DOM container. Later calls on the same root update it: React compares the new tree with the old one and changes only what differs, exactly as it does after a state change.
Most apps call render once at startup with <App />. Everything after that is handled by state, context and props inside the tree. Calling it again is mostly for embedding React in a non-React page, where outside code pushes new props in.
const root = createRoot(document.getElementById('root')); root.render(<App />);
Try it
Syntax
root.render(reactNode)
| Parameter | Description |
|---|---|
reactNode |
A React node: JSX such as <App />, a string, a number, null or an array of nodes. |
Returns undefined. There is no completion callback; use an effect or a ref inside the tree to learn when something has been committed.
Errors and edge cases
- After
root.unmount()the root is dead, andrenderthrowsCannot update an unmounted root. - Passing a second argument (the old callback form) is no longer supported and logs a warning in development.
Usage notes
- Same component type in the same position keeps its state. Rendering
<Greeting name="Bob" />over<Greeting name="Ann" />updates props only. Rendering a different component type resets the state of that subtree. - Calls are batched. React renders asynchronously, so several
rendercalls in the same tick produce one commit with the last tree, as the second example shows. Never rely on an in-between render happening. - The DOM is not updated yet when
renderreturns. Code that needs the new DOM should run in an effect, a ref callback, or afterflushSync. - Rendering
nullempties the tree but keeps the root alive (unlikeunmount, which also frees internal data structures). - Updating from outside React: keep the root in a module variable and call
renderwith new props, or give the app a small store that outside code can write to. The store approach avoids re-creating elements. - Do not call
renderinside a component body or during rendering; render must stay a pure calculation. Trigger it from event handlers or timers. - Server rendering uses a different set of functions, see hydrateRoot.