Skip to content

Commit

Permalink
fix: useEffect depencies
Browse files Browse the repository at this point in the history
  • Loading branch information
peritpatrio committed May 31, 2024
1 parent 93eba92 commit d646681
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions components/TopFade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div
Expand Down

0 comments on commit d646681

Please sign in to comment.