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(() => { if (ref.current) { if (open) { disableBodyScroll(ref.current) } else { enableBodyScroll(ref.current) } } return () => { clearAllBodyScrollLocks() } }, [open]) return ( {open ? (
{children}
) : null} ) } export default Sidebar