Home > Software design >  what does reactDOM.createroot does in React?
what does reactDOM.createroot does in React?

Time:10-16

In react applications we create I'm not able to understand, what does reactDOM.createroot does in React application? Does it create virtual DOM??

CodePudding user response:

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>
                );

CodePudding user response:

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

  • Related