aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-scroll-position.tsx
blob: c6ae9fdc5f5dca1c557b0f8a5e9fdac0b64b0578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
import { useEffect } from 'react';

/**
 * Execute the given function based on scroll position.
 *
 * @param scrollHandler - A callback function.
 */
export const useScrollPosition = (scrollHandler: () => void) => {
  useEffect(() => {
    window.addEventListener('scroll', scrollHandler);
    return () => window.removeEventListener('scroll', scrollHandler);
  }, [scrollHandler]);
};