Function: useThrottledValue()
useThrottledValue<
T>(value,delay,options?):T
Defined in: use-throttled-value.ts:44
Returns a throttled copy of value that updates at most once per delay
milliseconds. It is the value-based counterpart to useDebounce.
A throttle window starts when a change arrives while none is active. With
leading (default) the change is emitted immediately; with trailing
(default) the latest value seen during the window is emitted when it ends,
which starts a new window. The initial value is returned as-is on the first
render. With both options false, the returned value never updates.
Pending timers are cleared on unmount.
Type Parameters
T
T
The type of the value to throttle.
Parameters
value
T
The value to throttle.
delay
number
The minimum interval between updates, in milliseconds.
options?
Optional leading/trailing behavior.
Returns
T
The throttled value.
Examples
const [scrollY, setScrollY] = useState(0);
const throttledScrollY = useThrottledValue(scrollY, 200);
// Only emit at the end of each window
const throttledQuery = useThrottledValue(query, 500, { leading: false });
For a live, editable example, see the useThrottledValue docs page.