Skip to content

Commit

Permalink
Changed behavior burger-menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Chelakhovl committed Nov 28, 2024
1 parent a0ba214 commit eb3752c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions FrontEnd/src/context/BurgerMenuContext.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
Expand All @@ -20,7 +22,11 @@ export const BurgerMenuProvider = ({ children }) => {
return () => {
window.removeEventListener('resize', handleResize);
};
}, [isOpen]);
}, []);

useEffect(() => {
setIsOpen(false);
}, [pathname]);

return (
<BurgerMenuContext.Provider value={{ isOpen, toggleMenu }}>
Expand Down

0 comments on commit eb3752c

Please sign in to comment.