Skip to content

Commit 759f0d3

Browse files
fix(navigation): clean up global scroll listeners
Signed-off-by: Manishnemade12 <mnemade140@gmail.com>
1 parent 16010bb commit 759f0d3

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/sections/Company/Brand/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@ const easeOutCuaic = (t) => {
9191
const Brand = () => {
9292
const [scroll, setScroll] = useState(false);
9393
useEffect(() => {
94-
window.addEventListener("scroll", () =>
95-
window.scrollY > 510 ? setScroll(true) : setScroll(false)
96-
);
94+
const handleHeaderScroll = () => {
95+
window.scrollY > 510 ? setScroll(true) : setScroll(false);
96+
};
97+
98+
window.addEventListener("scroll", handleHeaderScroll);
99+
100+
return () => {
101+
window.removeEventListener("scroll", handleHeaderScroll);
102+
};
97103
}, []);
98104

99105
const [visibleSection, setVisibleSection] = useState();

src/sections/General/Navigation/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,15 @@ const Navigation = () => {
262262
}, [expand]);
263263

264264
useEffect(() => {
265-
window.addEventListener("scroll", () =>
266-
window.scrollY > 50 ? setScroll(true) : setScroll(false)
267-
);
265+
const handleScroll = () => {
266+
window.scrollY > 50 ? setScroll(true) : setScroll(false);
267+
};
268+
269+
window.addEventListener("scroll", handleScroll);
270+
271+
return () => {
272+
window.removeEventListener("scroll", handleScroll);
273+
};
268274
}, []);
269275

270276
const openDropDown = () => {

0 commit comments

Comments
 (0)