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

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

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



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

useAsyncBatchedCallback

Copy Markdown

Function: useAsyncBatchedCallback()
===================================

ts

function useAsyncBatchedCallback<TFn>(fn, options): (...args) => Promise<void>;


function useAsyncBatchedCallback<TFn>(fn, options): (...args) => Promise<void>;

Defined in: react-pacer/src/async-batcher/useAsyncBatchedCallback.ts:43

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

The batched async function will collect individual calls into batches and execute them when batch conditions are met (max size reached, wait time elapsed, or custom logic). The returned function always returns a promise that resolves with undefined (since the batch function processes multiple items together).

This hook provides a simpler API compared to useAsyncBatcher, making it ideal for basic async batching needs. However, it does not expose the underlying AsyncBatcher instance.

For advanced usage requiring features like:

  • Manual batch execution
  • Access to batch results and state
  • Custom useCallback dependencies

Consider using the useAsyncBatcher hook instead.

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

TFn extends AnyAsyncFunction

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

(items) => Promise<any>

### options

AsyncBatcherOptions<Parameters<TFn>[0]>

Returns
-------

ts

(...args): Promise<void>;


(...args): Promise<void>;

### Parameters #### args

...Parameters<TFn>

### Returns

Promise<void>

Example
-------

tsx

// Batch API requests
const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => {
  const results = await Promise.all(requests.map(req => fetch(req.url)));
  return results.map(res => res.json());
}, {
  maxSize: 10,   // Process when 10 requests collected
  wait: 1000     // Or after 1 second
});

// Use in event handlers
<button onClick={() => batchApiCall({ url: '/api/analytics', data: eventData })}>
  Track Event
</button>


// Batch API requests
const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => {
  const results = await Promise.all(requests.map(req => fetch(req.url)));
  return results.map(res => res.json());
}, {
  maxSize: 10,   // Process when 10 requests collected
  wait: 1000     // Or after 1 second
});

// Use in event handlers
<button onClick={() => batchApiCall({ url: '/api/analytics', data: eventData })}>
  Track Event
</button>

Edit on GitHub

useBatchedCallback

debounce

Partners Become a Partner

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

scarf analytics