function createThrottledValue<TValue>(value, initialOptions): [Accessor<TValue>, SolidThrottler<Setter<TValue>>]
function createThrottledValue<TValue>(value, initialOptions): [Accessor<TValue>, SolidThrottler<Setter<TValue>>]
Defined in: throttler/createThrottledValue.ts:35
A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window. This hook uses Solid's createSignal 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:
The throttled value will update according to the leading/trailing edge behavior specified in the options.
For more direct control over throttling behavior without Solid state management, consider using the lower-level createThrottler hook instead.
• TValue
Accessor<TValue>
ThrottlerOptions<Setter<TValue>>
[Accessor<TValue>, SolidThrottler<Setter<TValue>>]
// Basic throttling - update at most once per second
const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });
// Use the throttled value
console.log(throttledValue()); // Access the current throttled value
// Control the throttler
throttler.cancel(); // Cancel any pending updates
// Basic throttling - update at most once per second
const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });
// Use the throttled value
console.log(throttledValue()); // Access the current throttled value
// Control the throttler
throttler.cancel(); // Cancel any pending updates
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.