When creating react
applications, what does reactDOM.createroot
do? Does it create virtual DOM?
Asked
Active
Viewed 2,525 times
2

Captain Hat
- 2,444
- 1
- 14
- 31

Priya Kumari
- 43
- 1
- 4
-
1your question is already answered in React documentation here is the link - https://reactjs.org/docs/react-dom-client.html#:~:text=Reference-,createRoot(),createRoot(container)%3B%20root. – Rohit Bhati Oct 15 '22 at 09:41
2 Answers
1
createRoot() method is going to replace ReactDOM.render() in React 18.
I suggest looking at the docs: https://reactjs.org/docs/react-dom-client.html#createroot
And here's the link to another question about the deprecation of the render method: Deprecation notice: ReactDOM.render is no longer supported in React 18

ctkr
- 36
- 3
1
reactDOM.createroot
use to create new container in virtual dom
like you want to inject some component dynamically you can use is like this
//here is container where you will add dynamic dom
const root = ReactDOMClient.createRoot(document.getElementById('bodyArea'));
//here is dynamic dom
root.render(
<MyPopupModal>
<TestComonent></TestComponent>
</Modal>
);

Danyial Shahid Ali
- 517
- 8
- 24