ReactDOM.createPortal
returns an instance of ReactPortal , which is a valid ReactNode but not a valid DOM element. At the same time, the createPortal
component context will be respected. So I moved the function call inside the rendering method and solved the problem.
class Info extends React.Component {
render() {
return ReactDOM.createPortal(
<div ref={ el => this.tooltip = el }>{props.children}</div>,
document.body
);
}
componentDidMount() {
console.log(this.tooltip);
}
}
source
share