Last active
July 3, 2019 08:45
-
-
Save DubiousS/1934169d9ab838e49f6c444cdf6ddf8b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 * as React from 'react'; | |
import * as ReactDOM from 'react-dom'; | |
interface IPortalContentProps { | |
children: React.ReactNode; | |
} | |
const createPortal = () => { | |
const portalRef: React.RefObject<HTMLDivElement> = React.createRef(); | |
const Placeholder: React.FC = () => <div ref={portalRef} />; | |
const Content: React.FC<IPortalContentProps> = ({ children }): undefined | React.ReactPortal => { | |
return portalRef.current && ReactDOM.createPortal(children, portalRef.current); | |
}; | |
return { Placeholder, Content }; | |
}; | |
export default createPortal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment