From eb3752cf7d7788cc03188345b0f3a3b1f279e1df Mon Sep 17 00:00:00 2001 From: Leonid Chelakhov Date: Thu, 28 Nov 2024 17:59:04 +0300 Subject: [PATCH] Changed behavior burger-menu --- FrontEnd/src/context/BurgerMenuContext.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/FrontEnd/src/context/BurgerMenuContext.js b/FrontEnd/src/context/BurgerMenuContext.js index 04e49de7..b118a0dd 100644 --- a/FrontEnd/src/context/BurgerMenuContext.js +++ b/FrontEnd/src/context/BurgerMenuContext.js @@ -1,16 +1,18 @@ import React, { createContext, useState, useContext, useEffect } from 'react'; import PropTypes from 'prop-types'; +import { useLocation } from 'react-router-dom'; const BurgerMenuContext = createContext(); export const BurgerMenuProvider = ({ children }) => { const [isOpen, setIsOpen] = useState(false); + const { pathname } = useLocation(); const toggleMenu = () => setIsOpen((prev) => !prev); useEffect(() => { const handleResize = () => { - if (window.innerWidth > 1200 && isOpen) { + if (window.innerWidth > 1200) { setIsOpen(false); } }; @@ -20,7 +22,11 @@ export const BurgerMenuProvider = ({ children }) => { return () => { window.removeEventListener('resize', handleResize); }; - }, [isOpen]); + }, []); + + useEffect(() => { + setIsOpen(false); + }, [pathname]); return (