Consider the following example:
class GridContainer extends React.Component {
...
render (){
return <div>
<Pagination portalId="portal-id"></>
<Grid ...>
</div>
}
}
class Grid extends React.Component {
...
render (){
return <div>
<div id="portal-id"></>
<table ...>
</div>
}
}
class Pagination extends React.Component {
...
render (){
return return ReactDOM.createPortal(<div>Paginator DOM...</div>, document.getElementById(this.props.portalId));
}
}
Is it safe to render a portal inside other components DOM? I've tested it and it works, but I don't know if this is reliable. The Portals doc mention that you can render a portal in a DOM node but nothing about components DOM.
Why is this different (speculating here)? while updating the portal parent component, in the reconciliation process the diff might find the inconsistency and remove the portal node.
From my testing, the above doesn't happen but I don't know if I can assume that react handles it. So here comes the Q:
Is it safe to render a portal into another component DOM?