Last active
March 3, 2020 09:42
-
-
Save roeib/4279708bd90cbf0426c7da435f18893f to your computer and use it in GitHub Desktop.
This file contains 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 { useEffect } from "react"; | |
import { createPortal } from "react-dom"; | |
const Portal = ({children}) => { | |
const mount = document.getElementById("portal-root"); | |
const el = document.createElement("div"); | |
useEffect(() => { | |
mount.appendChild(el); | |
return () => mount.removeChild(el); | |
}, [el, mount]); | |
return createPortal(children, el) | |
}; | |
export default Portal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment