Framework
Version
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference

createThrottledValue

Function: createThrottledValue()

ts
function createThrottledValue<TValue, TSelected>(
   value, 
   initialOptions, 
   selector?): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>]
function createThrottledValue<TValue, TSelected>(
   value, 
   initialOptions, 
   selector?): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>]

Defined in: throttler/createThrottledValue.ts:38

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:

  • An accessor function that provides the throttled value
  • The throttler instance with control methods

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.

Type Parameters

TValue

TSelected = ThrottlerState<Setter<TValue>>

Parameters

value

Accessor<TValue>

initialOptions

ThrottlerOptions<Setter<TValue>>

selector?

(state) => TSelected

Returns

[Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>]

Example

tsx
// 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
Subscribe to Bytes

Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.

Bytes

No spam. Unsubscribe at any time.