import { FC, useRef, useEffect } from 'react' import Portal from '@reach/portal' import s from './Modal.module.css' import { Cross } from '@components/icons' import { disableBodyScroll, enableBodyScroll, clearAllBodyScrollLocks, } from 'body-scroll-lock' interface Props { className?: string children?: any open?: boolean onClose: () => void } const Modal: FC = ({ children, open, onClose }) => { const ref = useRef() as React.MutableRefObject useEffect(() => { if (ref.current) { if (open) { disableBodyScroll(ref.current) } else { enableBodyScroll(ref.current) } } return () => { clearAllBodyScrollLocks() } }, [open]) return ( {open ? (
{children}
) : null}
) } export default Modal