import React, { useLayoutEffect, useState } from 'react'; import ReactDOM from 'react-dom'; interface IPortal { children: React.ReactNode } /** * Portal */ const Portal: React.FC = ({ children }) => { const [isRendered, setIsRendered] = useState(false); useLayoutEffect(() => { setIsRendered(true); }, []); if (!isRendered) { return null; } return ( ReactDOM.createPortal( children, document.getElementById('soapbox') as HTMLDivElement, ) ); }; export default Portal;