import { useEffect, useRef } from 'rax'; import findDOMNode from 'rax-find-dom-node'; import createPortal from 'rax-create-portal'; function getPortal(portal) { if (typeof portal === 'function') { return portal(); } else if (portal === true) { return document.body; } else { return portal; } } const Portal = ({ portal, children }) => { const p = findDOMNode(getPortal(portal)); const el = useRef(document.createElement('div')); useEffect(() => { p.appendChild(el.current); return () => { el.current.parentNode.removeChild(el.current); }; }, []); return createPortal(children, el.current); }; export default Portal;