Skip to content

Instantly share code, notes, and snippets.

@DubiousS
Last active July 3, 2019 08:45
Show Gist options
  • Save DubiousS/1934169d9ab838e49f6c444cdf6ddf8b to your computer and use it in GitHub Desktop.
Save DubiousS/1934169d9ab838e49f6c444cdf6ddf8b to your computer and use it in GitHub Desktop.
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