import { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
const propTypes = {
children: PropTypes.any,
};
export default class RenderToLayer extends Component {
componentDidMount() {
this.popup = document.createElement('div');
document.body.appendChild(this.popup);
this.renderLayer();
}
componentDidUpdate() {
this.renderLayer();
}
componentWillUnmount() {
this.unrenderLayer();
}
unrenderLayer() {
if (!this.popup) {
return;
}
ReactDOM.unmountComponentAtNode(this.popup);
document.body.removeChild(this.popup);
this.popup = null;
}
renderLayer() {
ReactDOM.render(this.props.children, this.popup);
}
render() {
return null;
}
}
RenderToLayer.propTypes = propTypes;