Reference: https://reactjs.org/docs/portals.html
When to use it
Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. Examples of this:
- Modals
- Dialogs and error messages
Creation
In the /public/index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Some code -->
</head>
<body>
<!-- Some code -->
<!-- For Portals -->
<div id="overlays"></div>
<!-- Main React-->
<div id="root"></div>
<!-- Some code -->
</body>
</html>Use
in the /src/components/UI/Modal.js file: