Skip to content
Tutorials Center
My learning

Topics

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.

JSX
const root = createRoot(document.getElementById('root'));
root.render(<App />);

Try it

Render again to update
Calls in the same tick are batched

Syntax

JSX
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, and render throws Cannot 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 render calls 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 render returns. Code that needs the new DOM should run in an effect, a ref callback, or after flushSync.
  • Rendering null empties the tree but keeps the root alive (unlike unmount, which also frees internal data structures).
  • Updating from outside React: keep the root in a module variable and call render with 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 render inside 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.