Skip to content

Commit c353dd4

Browse files
committed
docs: add note about root.render microtask scheduling
1 parent 5138e60 commit c353dd4

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/content/reference/react-dom/client/createRoot.md

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ React will display `<App />` in the `root`, and take over managing the DOM insid
9090
9191
* If you call `render` on the same root more than once, React will update the DOM as necessary to reflect the latest JSX you passed. React will decide which parts of the DOM can be reused and which need to be recreated by ["matching it up"](/learn/preserving-and-resetting-state) with the previously rendered tree. Calling `render` on the same root again is similar to calling the [`set` function](/reference/react/useState#setstate) on the root component: React avoids unnecessary DOM updates.
9292
93+
* Although rendering is synchronous once it starts, calling `root.render(...)` schedules the render in a microtask. This means code after `root.render()` will run before any effects (`useLayoutEffect`, `useEffect`) are fired. This behavior is usually fine and rarely needs adjustment. However, in rare cases where effect timing matters, you can wrap `root.render(...)` in [`flushSync`](https://react.dev/reference/react-dom/client/flushSync) to ensure everything runs synchronously.
94+
9395
---
9496
9597
### `root.unmount()` {/*root-unmount*/}

0 commit comments

Comments
 (0)