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

createThrottledValue

Function: createThrottledValue()

ts
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:

  • 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

Parameters

value

Accessor<TValue>

initialOptions

ThrottlerOptions<Setter<TValue>>

Returns

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

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.