Skip to Content
⭐️ Leave a star →
HooksuseThrottle

useThrottle

Two related utilities for throttling — emitting at most once per delay ms. Use them for derived state from high-frequency events (scroll, mousemove, drag) where you want regular sampling rather than waiting for inactivity.

  • useThrottle(value, delay) — throttles a value.
  • useThrottledCallback(callback, delay) — returns a stable, throttled callback that fires on the leading edge; trailing calls within the delay window are dropped.

Throttling a value

import { useEffect, useState } from 'react' import { useThrottle } from '@wire-ui/react' function ScrollIndicator() { const [scrollY, setScrollY] = useState(0) const throttledScrollY = useThrottle(scrollY, 100) useEffect(() => { const onScroll = () => setScrollY(window.scrollY) window.addEventListener('scroll', onScroll) return () => window.removeEventListener('scroll', onScroll) }, []) return <p>Scrolled (sampled): {Math.round(throttledScrollY)}</p> }

Throttling a callback

import { useThrottledCallback } from '@wire-ui/react' function MouseTracker() { const trackPointer = useThrottledCallback((event: React.MouseEvent) => { analytics.track('pointermove', { x: event.clientX, y: event.clientY }) }, 200) return <div onMouseMove={trackPointer} /> }

Parameters

useThrottle

ParamTypeDescription
valueTValue to throttle.
delaynumberMinimum milliseconds between emissions.

useThrottledCallback

ParamTypeDescription
callback(...args) => voidFunction to throttle.
delaynumberMinimum milliseconds between invocations.
Last updated on

MIT License © 2026 wire-ui

useThrottle – Wire UI