📄 tanstack/pacer/latest/docs/framework/solid/reference/functions/createRateLimitedSignal

File: createRateLimitedSignal.md | Updated: 11/15/2025

Source: https://tanstack.com/pacer/latest/docs/framework/solid/reference/functions/createRateLimitedSignal



TanStack

Pacer v0v0

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

Solid logo

Solid

Version

Latest

Search...

+ K

Menu

Getting Started

Guides

API Reference

Debouncer API Reference

Throttler API Reference

Rate Limiter API Reference

Queue API Reference

Batcher API Reference

Debouncer Examples

Throttler Examples

Rate Limiter Examples

Queue Examples

Batcher Examples

Framework

Solid logo

Solid

Version

Latest

Menu

Getting Started

Guides

API Reference

Debouncer API Reference

Throttler API Reference

Rate Limiter API Reference

Queue API Reference

Batcher API Reference

Debouncer Examples

Throttler Examples

Rate Limiter Examples

Queue Examples

Batcher Examples

On this page

createRateLimitedSignal

Copy Markdown

Function: createRateLimitedSignal()
===================================

ts

function createRateLimitedSignal<TValue, TSelected>(
   value, 
   initialOptions, 
   selector?): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];


function createRateLimitedSignal<TValue, TSelected>(
   value, 
   initialOptions, 
   selector?): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];

Defined in: rate-limiter/createRateLimitedSignal.ts:95

A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window. This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.

Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.

The rate limiter supports two types of windows:

  • 'fixed': A strict window that resets after the window period. All updates within the window count towards the limit, and the window resets completely after the period.
  • 'sliding': A rolling window that allows updates as old ones expire. This provides a more consistent rate of updates over time.

For smoother update patterns, consider:

  • createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)
  • createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)

Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.

The hook returns a tuple containing:

  • The rate-limited state value accessor
  • A rate-limited setter function that respects the configured limits
  • The rateLimiter instance for additional control

For more direct control over rate limiting without state management, consider using the lower-level createRateLimiter hook instead.

State Management and Selector
-----------------------------

The hook uses TanStack Store for reactive state management via the underlying rate limiter instance. The selector parameter allows you to specify which rate limiter state changes will trigger reactive updates, optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.

By default, there will be no reactive state subscriptions and you must opt-in to state tracking by providing a selector function. This prevents unnecessary reactive updates and gives you full control over when your component subscribes to state changes. Only when you provide a selector will the reactive system track the selected state values.

Available rate limiter state properties:

  • callsInWindow: Number of calls made in the current window
  • remainingInWindow: Number of calls remaining in the current window
  • windowStart: Unix timestamp when the current window started
  • nextWindowStart: Unix timestamp when the next window will start
  • msUntilNextWindow: Milliseconds until the next window starts
  • isAtLimit: Whether the call limit for the current window has been reached
  • status: Current status ('disabled' | 'idle' | 'at-limit')

Type Parameters
---------------
### TValue

TValue

### TSelected

TSelected = { }

Parameters
----------
### value

TValue

### initialOptions

RateLimiterOptions<Setter<TValue>>

### selector?

(state) => TSelected

Returns
-------

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

Example
-------

tsx

// Default behavior - no reactive state subscriptions
const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
  limit: 5,
  window: 60000,
  windowType: 'sliding'
});

// Opt-in to reactive updates when limit state changes (optimized for UI feedback)
const [value, setValue, rateLimiter] = createRateLimitedSignal(
  0,
  { limit: 5, window: 60000 },
  (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })
);

// With rejection callback and fixed window
const [value, setValue] = createRateLimitedSignal(0, {
  limit: 3,
  window: 5000,
  windowType: 'fixed',
  onReject: (rateLimiter) => {
    alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
  }
});

// Access rateLimiter state via signals
const handleSubmit = () => {
  const remaining = rateLimiter.state().remainingInWindow;
  if (remaining > 0) {
    setValue(newValue);
  } else {
    showRateLimitWarning();
  }
};


// Default behavior - no reactive state subscriptions
const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
  limit: 5,
  window: 60000,
  windowType: 'sliding'
});

// Opt-in to reactive updates when limit state changes (optimized for UI feedback)
const [value, setValue, rateLimiter] = createRateLimitedSignal(
  0,
  { limit: 5, window: 60000 },
  (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })
);

// With rejection callback and fixed window
const [value, setValue] = createRateLimitedSignal(0, {
  limit: 3,
  window: 5000,
  windowType: 'fixed',
  onReject: (rateLimiter) => {
    alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
  }
});

// Access rateLimiter state via signals
const handleSubmit = () => {
  const remaining = rateLimiter.state().remainingInWindow;
  if (remaining > 0) {
    setValue(newValue);
  } else {
    showRateLimitWarning();
  }
};

Edit on GitHub

createRateLimiter

createRateLimitedValue

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics