Skip to content

Instantly share code, notes, and snippets.

@DiegoPinho
Created November 21, 2017 20:38
Show Gist options
  • Save DiegoPinho/76a638fdec3b9e1da976309ae153c895 to your computer and use it in GitHub Desktop.
Save DiegoPinho/76a638fdec3b9e1da976309ae153c895 to your computer and use it in GitHub Desktop.
const modal = document.getElementById('modal');
class Modal extends React.Component {
constructor(props) {
super(props);
this.el = document.createElement('div');
}
componentDidMount() {
modal.appendChild(this.el);
}
componentWillUnmount() {
modal.removeChild(this.el);
}
render() {
return ReactDOM.createPortal(this.props.children,this.el);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment