📄 tanstack/pacer/latest/docs/framework/react/reference/functions/useAsyncRateLimitedCallback

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

Source: https://tanstack.com/pacer/latest/docs/framework/react/reference/functions/useAsyncRateLimitedCallback



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

React logo

React

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

TanStack Query Examples

Framework

React logo

React

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

TanStack Query Examples

On this page

useAsyncRateLimitedCallback

Copy Markdown

Function: useAsyncRateLimitedCallback()
=======================================

ts

function useAsyncRateLimitedCallback<TFn>(fn, options): (...args) => Promise<ReturnType<TFn>>;


function useAsyncRateLimitedCallback<TFn>(fn, options): (...args) => Promise<ReturnType<TFn>>;

Defined in: react-pacer/src/async-rate-limiter/useAsyncRateLimitedCallback.ts:59

A React hook that creates a rate-limited version of an async callback function. This hook is a convenient wrapper around the useAsyncRateLimiter hook, providing a stable, async rate-limited function reference for use in React components.

Async rate limiting is a "hard limit" approach for async functions: it allows all calls until the limit is reached, then blocks (rejects) subsequent calls until the window resets. Unlike throttling or debouncing, it does not attempt to space out or collapse calls. This can lead to bursts of rapid executions followed by periods where all calls are blocked.

The async rate limiter supports two types of windows:

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

For smoother execution patterns, consider:

  • useAsyncThrottledCallback: When you want consistent spacing between executions (e.g. UI updates)
  • useAsyncDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input)

Async rate limiting should primarily be used when you need to enforce strict limits on async operations, like API rate limits or other scenarios requiring hard caps on execution frequency.

This hook provides a simpler API compared to useAsyncRateLimiter, making it ideal for basic async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance.

For advanced usage requiring features like:

  • Manual cancellation
  • Access to execution counts
  • Custom useCallback dependencies

Consider using the useAsyncRateLimiter hook instead.

Type Parameters
---------------
### TFn

TFn extends AnyAsyncFunction

Parameters
----------
### fn

TFn

### options

AsyncRateLimiterOptions<TFn>

Returns
-------

ts

(...args): Promise<ReturnType<TFn>>;


(...args): Promise<ReturnType<TFn>>;

### Parameters #### args

...Parameters<TFn>

### Returns

Promise<ReturnType<TFn>>

Example
-------

tsx

// Rate limit async API calls to maximum 5 calls per minute with a sliding window
const makeApiCall = useAsyncRateLimitedCallback(
  async (data: ApiData) => {
    return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });
  },
  {
    limit: 5,
    window: 60000, // 1 minute
    windowType: 'sliding',
    onReject: () => {
      console.warn('API rate limit reached. Please wait before trying again.');
    }
  }
);


// Rate limit async API calls to maximum 5 calls per minute with a sliding window
const makeApiCall = useAsyncRateLimitedCallback(
  async (data: ApiData) => {
    return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });
  },
  {
    limit: 5,
    window: 60000, // 1 minute
    windowType: 'sliding',
    onReject: () => {
      console.warn('API rate limit reached. Please wait before trying again.');
    }
  }
);

Edit on GitHub

useAsyncRateLimiter

QueuerOptions

Partners Become a Partner

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

scarf analytics