import s from './Sidebar.module.css' import Portal from '@reach/portal' import { FC, useEffect, useRef } from 'react' import { disableBodyScroll, enableBodyScroll, clearAllBodyScrollLocks, } from 'body-scroll-lock' interface Props { children: any open: boolean onClose: () => void } const Sidebar: FC = ({ children, open = false, onClose }) => { const ref = useRef() as React.MutableRefObject useEffect(() => { setTimeout(() => { if (ref.current && open) { window.document.body.style.overflow = 'hidden' disableBodyScroll(ref.current) } else { window.document.body.style.overflow && setTimeout(() => (window.document.body.style.overflow = 'unset'), 30) !!ref.current && enableBodyScroll(ref.current) } }, 30) return () => { clearAllBodyScrollLocks() } }, [open]) return ( {open ? (
{children}
) : null} ) } export default Sidebar