Skip to content

Instantly share code, notes, and snippets.

@biancadragomir
Created October 15, 2021 15:48
Show Gist options
  • Save biancadragomir/ab6880227d0aef538627bca60fef747e to your computer and use it in GitHub Desktop.
Save biancadragomir/ab6880227d0aef538627bca60fef747e to your computer and use it in GitHub Desktop.
import { useEffect } from 'react';
export const useOnScrollEffect = (
fun: React.EffectCallback,
elementId: string
) =>
useEffect(() => {
document.getElementById(elementId)?.addEventListener('scroll', fun);
return () => window.removeEventListener('scroll', fun);
}, [fun]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment