Skip to content

Commit

Permalink
Changed burger menu context
Browse files Browse the repository at this point in the history
  • Loading branch information
Chelakhovl committed Nov 28, 2024
1 parent ebcf9e8 commit a0ba214
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion FrontEnd/src/context/BurgerMenuContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useState, useContext } from 'react';
import React, { createContext, useState, useContext, useEffect } from 'react';
import PropTypes from 'prop-types';

const BurgerMenuContext = createContext();
Expand All @@ -8,6 +8,20 @@ export const BurgerMenuProvider = ({ children }) => {

const toggleMenu = () => setIsOpen((prev) => !prev);

useEffect(() => {
const handleResize = () => {
if (window.innerWidth > 1200 && isOpen) {
setIsOpen(false);
}
};

window.addEventListener('resize', handleResize);

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

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

0 comments on commit a0ba214

Please sign in to comment.