Why do we use <div>#root instead of <body>?

Viewed 2244

So, as I understand a React app can be rendered inside pretty much any HTML element we point to by a selector. Why is the convention to use additional <div> with id of root, instead of just <body>?

1 Answers

From the creator of Redux (Dan Abramov), this is what he has to say about rendering to the body.

If you render directly into document.body, you risk collisions with scripts that do something with it (e.g. Google Font Loader or third party browser extensions) which produce very weird and hard to debug errors in production. React warns you if you attempt to do this.

https://github.com/facebook/create-react-app/issues/1568

Related