From 0aade3968c418e70c5037a81c295739b2eac1456 Mon Sep 17 00:00:00 2001 From: Olly Swanson Date: Thu, 17 Dec 2020 16:21:52 +0100 Subject: [PATCH] fixed handleScroll event handler --- components/common/Navbar/Navbar.tsx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/components/common/Navbar/Navbar.tsx b/components/common/Navbar/Navbar.tsx index 24a2b5757..d2d2b2d79 100644 --- a/components/common/Navbar/Navbar.tsx +++ b/components/common/Navbar/Navbar.tsx @@ -9,31 +9,31 @@ import throttle from 'lodash.throttle' const Navbar: FC = () => { const [hasScrolled, setHasScrolled] = useState(false) - const handleScroll = () => { - const offset = 0 - const { scrollTop } = document.documentElement - const scrolled = scrollTop > offset - setHasScrolled(scrolled) - } - useEffect(() => { - document.addEventListener('scroll', throttle(handleScroll, 200)) + const handleScroll = throttle(() => { + const offset = 0 + const { scrollTop } = document.documentElement + const scrolled = scrollTop > offset + setHasScrolled(scrolled) + }, 200) + + document.addEventListener('scroll', handleScroll) return () => { document.removeEventListener('scroll', handleScroll) } - }, [handleScroll]) + }, []) return (
-
-
+
+
-
-
+
-
+