Guest User

Untitled

a guest
Jun 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. import { Component } from "react";
  2. import ReactDOM from "react-dom";
  3.  
  4. const portalRoot = document.getElementById("portal");
  5.  
  6. export default class Portal extends Component {
  7. constructor(props){
  8. super(props);
  9. this.el = document.createElement("div");
  10. }
  11. componentDidMount = () => {
  12. portalRoot.appendChild(this.el);
  13. }
  14. componentWillUnmount = () => {
  15. portalRoot.removeChild(this.el);
  16. }
  17. render(){
  18. const { children } = this.props;
  19. return ReactDOM.createPortal(children,this.el);
  20. }
  21. }
Add Comment
Please, Sign In to add comment