Skip to content

Instantly share code, notes, and snippets.

@roeib
Last active March 3, 2020 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roeib/4279708bd90cbf0426c7da435f18893f to your computer and use it in GitHub Desktop.
Save roeib/4279708bd90cbf0426c7da435f18893f to your computer and use it in GitHub Desktop.
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