Skip to content

Commit

Permalink
hide mobile menu on page change
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikcoskun committed Oct 11, 2024
1 parent cc62f27 commit 9c6590b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions components/layout/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import { NavbarDownloadButton } from "./NavbarDownloadButton";
// Styles
import style from "./Navbar.module.scss";
import classNames from "classnames/bind";
import { usePathname } from "next/navigation";

const cx = classNames.bind(style);

export function Navbar() {
const path = usePathname();
const [mobileMenu, setMobileMenu] = React.useState(false);

React.useEffect(() => {
Expand All @@ -25,11 +27,8 @@ export function Navbar() {
}, [mobileMenu]);

React.useEffect(() => {
const listener = () => setMobileMenu(false);

window.addEventListener("hashchange", listener);
return () => window.removeEventListener("hashchange", listener);
}, []);
setMobileMenu(false);
}, [path]);

return (
<header role="banner" className={cx("container", "contentPadding")}>
Expand Down

0 comments on commit 9c6590b

Please sign in to comment.