Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloydjatkinson/96e53a0c398848e678773547a4f29684 to your computer and use it in GitHub Desktop.
Save lloydjatkinson/96e53a0c398848e678773547a4f29684 to your computer and use it in GitHub Desktop.
export const MobileNavigationMenu = ({ targetSelector }: { targetSelector: string }) => {
if (!document) {
// We're in SSR/SSG. Render fallback content of a menu button in the closed stated.
return <MenuButton isOpen={ false } />;
}
const menu = document.querySelector(targetSelector);
if (!menu) return null;
const [isOpen, setIsOpen] = useState(false);
useEffect(() => {
if (isOpen) {
menu.classList.remove('hidden');
menu.classList.add('block');
} else {
menu.classList.remove('block');
menu.classList.add('hidden');
}
}, [isOpen]);
return (
<>
{ isOpen }
<MenuButton isOpen={ isOpen } onChange={ setIsOpen } />
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment