Does the Root Element Implicitly Have the ID "root"? - Create a Simple JSX Element - Front End Development Libraries

Hey everyone :wave: :smile:

In the React section of the Front End Development Libraries course, the first lesson / challenge, “Create a Simple JSX Element”, contains the following paragraph:

It’s worth noting that under the hood the challenges are calling ReactDOM.render(JSX, document.getElementById('root')) . This function call is what places your JSX into React’s own lightweight representation of the DOM. React then uses snapshots of its own DOM to optimize updating only specific parts of the actual DOM.

Does the fact that the root element is being accessed by ID, rather than by type, imply that the root element always implicitly has the ID “root”, or is this something that is just being added by freeCodeCamp in the background for convenience?

Thanks!

No, the id isn’t implicit you add it to the HTML, and it doesn’t have to be "root", it doesn’t even have to be an id. The second argument to render() just has to be an element. You can use any type of selector.

Using an id of "root" or "app" are the two most commonly used.


The API has been updated as well.

1 Like