Created
September 17, 2018 06:44
-
-
Save int64ago/c5c3b4a9e20758b03efcd20c5374c640 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import ReactDOM from 'react-dom'; | |
export default Comp => ( | |
class HOC extends Component { | |
constructor(props) { | |
super(props); | |
this.el = document.createElement('div'); | |
} | |
componentDidMount() { | |
document.body.appendChild(this.el); | |
} | |
componentWillUnmount() { | |
this.el.parentNode.removeChild(this.el); | |
} | |
render() { | |
return ReactDOM.createPortal(<Comp {...this.props} />, this.el); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment