Skip to content

Commit eca7e29

Browse files
committed
added example
1 parent 125614a commit eca7e29

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ React will display `<App />` in the `root`, and take over managing the DOM insid
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
9393
* Although rendering is synchronous once it starts, `root.render(...)` is not. This means code after `root.render()` may run before any effects (`useLayoutEffect`, `useEffect`) of that specific render are fired. This is usually fine and rarely needs adjustment. In rare cases where effect timing matters, you can wrap `root.render(...)` in [`flushSync`](https://react.dev/reference/react-dom/client/flushSync) to ensure the initial render runs fully synchronously.
94+
95+
```js
96+
const root = createRoot(document.getElementById('root'));
97+
root.render(<App />);
98+
// 🚩 The HTML will not include the rendered <App /> yet:
99+
console.log(document.body.innerHTML);
100+
```
94101
95102
---
96103

0 commit comments

Comments
 (0)