Skip to content

Commit

Permalink
Merge pull request #990 from ita-social-projects/989-fix/burger-menu-…
Browse files Browse the repository at this point in the history
…resize-issue

989 fix/burger menu resize issue
  • Loading branch information
Chelakhovl authored Nov 29, 2024
2 parents ebcf9e8 + eb3752c commit 60231dd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion FrontEnd/src/context/BurgerMenuContext.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import React, { createContext, useState, useContext } from 'react';
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) {
setIsOpen(false);
}
};

window.addEventListener('resize', handleResize);

return () => {
window.removeEventListener('resize', handleResize);
};
}, []);

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

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

0 comments on commit 60231dd

Please sign in to comment.