How to use the @react-hook/throttle.useThrottle function in @react-hook/throttle

To help you get started, we’ve selected a few @react-hook/throttle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jaredLunde / react-hook / packages / window-scroll / src / index.ts View on Github external
export const useWindowScroll = (fps = 30): number => {
  const [scrollY, setThrottledScroll] = useThrottle(
    typeof window === 'undefined' ? 0 : getScrollY,
    fps,
    true
  )

  useEffect(() => {
    const handleScroll = (): void => setThrottledScroll(getScrollY())
    window.addEventListener('scroll', handleScroll)
    return (): void => {
      window.removeEventListener('scroll', handleScroll)
    }
  }, emptyArr)

  return scrollY
}

@react-hook/throttle

A React hook for throttling setState and other callbacks

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis