https://github.com/facebook/react/blob/main/CHANGELOG.md#react-dom-client
These new APIs are now exported from react-dom/client
:
createRoot
: New method to create a root to render
or unmount
. Use it instead of ReactDOM.render
. New features in React 18 don't work without it.https://react.dev/reference/react-dom/client/createRoot
• 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” with the previously rendered tree. Calling render
on the same root again is similar to calling the set
function on the root component: React avoids unnecessary DOM updates.