From d646681fe339d54e58420fcaa287f621bf398980 Mon Sep 17 00:00:00 2001 From: Petri Partio Date: Fri, 31 May 2024 14:18:14 +0300 Subject: [PATCH] fix: useEffect depencies --- components/TopFade.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/TopFade.tsx b/components/TopFade.tsx index 1d0b01a..bbf5538 100644 --- a/components/TopFade.tsx +++ b/components/TopFade.tsx @@ -11,17 +11,17 @@ const calculatedBrightnessValue = () => { export default function TopFade() { const [brightness, setBrightness] = useState(calculatedBrightnessValue()); - const handleScroll = (event: Event) => { - if (window.scrollY > 200 && brightness === 0.5) return; - setBrightness(calculatedBrightnessValue()); - }; - useEffect(() => { + const handleScroll = (event: Event) => { + if (window.scrollY > 200 && brightness === 0.5) return; + setBrightness(calculatedBrightnessValue()); + }; + document.addEventListener('scroll', handleScroll, true); return () => { document.removeEventListener('scroll', handleScroll, true); }; - }, []); + }, [brightness]); return (