Skip to content

Instantly share code, notes, and snippets.

@int64ago
Created September 17, 2018 06:44
Show Gist options
  • Save int64ago/c5c3b4a9e20758b03efcd20c5374c640 to your computer and use it in GitHub Desktop.
Save int64ago/c5c3b4a9e20758b03efcd20c5374c640 to your computer and use it in GitHub Desktop.
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