function useThrottledValue<TValue>(value, options): [TValue, Throttler<Dispatch<SetStateAction<TValue>>>]
function useThrottledValue<TValue>(value, options): [TValue, Throttler<Dispatch<SetStateAction<TValue>>>]
Defined in: react-pacer/src/throttler/useThrottledValue.ts:32
A high-level React hook that creates a throttled version of a value that updates at most once within a specified time window. This hook uses React's useState internally to manage the throttled state.
Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes. This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.
The hook returns a tuple containing:
For more direct control over throttling behavior without React state management, consider using the lower-level useThrottler hook instead.
• TValue
TValue
ThrottlerOptions<Dispatch<SetStateAction<TValue>>>
[TValue, Throttler<Dispatch<SetStateAction<TValue>>>]
// Basic throttling - update at most once per second
const [throttledValue, throttler] = useThrottledValue(rawValue, { wait: 1000 });
// With custom leading/trailing behavior
const [throttledValue, throttler] = useThrottledValue(rawValue, {
wait: 1000,
leading: true, // Update immediately on first change
trailing: false // Skip trailing edge updates
});
// Basic throttling - update at most once per second
const [throttledValue, throttler] = useThrottledValue(rawValue, { wait: 1000 });
// With custom leading/trailing behavior
const [throttledValue, throttler] = useThrottledValue(rawValue, {
wait: 1000,
leading: true, // Update immediately on first change
trailing: false // Skip trailing edge updates
});
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.