Skip to content

Commit

Permalink
fix: add window resize check for header
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixpereira committed Feb 12, 2024
1 parent 5206fa0 commit 9bcc739
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ export default function Header() {

useEffect(() => {
window.addEventListener('scroll', handleScroll);
window.addEventListener('resize', handleResize);

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

const handleResize = () => {
if (window.innerWidth >= 768) {
setIsMenuOpen(false);
}
};

const handleScroll = () => {
const scrollPosition = window.scrollY;
setIsScrolled(scrollPosition > 0);
Expand Down

0 comments on commit 9bcc739

Please sign in to comment.