Skip to content

Commit 7ad8b20

Browse files
Merge pull request #7617 from Manishnemade12/Uncleaned
fix(navigation): clean up leaked global scroll listeners
2 parents 3632992 + 140d626 commit 7ad8b20

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

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
@@ -272,9 +272,15 @@ const Navigation = () => {
272272
}, [expand]);
273273

274274
useEffect(() => {
275-
window.addEventListener("scroll", () =>
276-
window.scrollY > 50 ? setScroll(true) : setScroll(false),
277-
);
275+
const handleScroll = () => {
276+
window.scrollY > 50 ? setScroll(true) : setScroll(false);
277+
};
278+
279+
window.addEventListener("scroll", handleScroll);
280+
281+
return () => {
282+
window.removeEventListener("scroll", handleScroll);
283+
};
278284
}, []);
279285

280286
const openDropDown = () => {

0 commit comments

Comments
 (0)