DEV Community

Siddhartha Gupta
Siddhartha Gupta

Posted on

I'm learning React from a "First Principles" approach. I am concerned that a undefined variable can be rendered in root.render; error prone. Would anyone know why is this allowed? root.render().

Top comments (1)

Collapse
 
kurealnum profile image
Oscar

root.render() should render the base of your application. The base component that gets rendered (usually App.jsx) should never be null. And if you're getting your root like this (or a similar way -- there are probably different ways to go about this):

ReactDOM.createRoot(document.getElementById("root"))
Enter fullscreen mode Exit fullscreen mode

Then as long as your index.html has a <div id="root"></div> in it, document.getElementById("root") won't ever be null either.