slate/components/core/ModalPortal.js
Aminejv 0c4ecd9025 feat(modals): add portal to display modals in
- feat(_document): render portals in the div element with id browser_extension

- feat(ModalPortal): useReactDom.createPortal to render childrens
2021-09-17 14:44:29 -07:00

15 lines
375 B
JavaScript

import * as React from "react";
import * as ReactDOM from "react-dom";
export const ModalPortal = ({ children }) => {
const [mounted, setMounted] = React.useState(false);
React.useEffect(() => {
setMounted(true);
return () => setMounted(false);
}, []);
return mounted ? ReactDOM.createPortal(children, document.getElementById("modals_portal")) : null;
};