Skip to content
usefy

useThrottle

Timing & async

A high-performance React hook for throttling values with leading/trailing edge support

Install

$ npm install @usefy/use-throttle

Quick start

useThrottle.tsx
import { useThrottle } from "@usefy/use-throttle";

function ScrollTracker() {
  const [scrollY, setScrollY] = useState(0);
  const throttledScrollY = useThrottle(scrollY, 100);

  useEffect(() => {
    const handleScroll = () => setScrollY(window.scrollY);
    window.addEventListener("scroll", handleScroll);
    return () => window.removeEventListener("scroll", handleScroll);
  }, []);

  return <div>Scroll position: {throttledScrollY}px</div>;
}

API reference

useThrottle<T>(value, delay?, options?)

A hook that returns a throttled version of the provided value, limiting updates to at most once per interval.

Parameters

ParameterTypeDefaultDescription
valueTThe value to throttle
delaynumber500The throttle interval in milliseconds
optionsUseThrottleOptions{}Additional configuration options

Options

OptionTypeDefaultDescription
leadingbooleantrueUpdate on the leading edge (first change)
trailingbooleantrueUpdate on the trailing edge (after interval)

Returns

TypeDescription
TThe throttled value

Go deeper

This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.

More in timing & async