Batch query updates
Reduce redundant subscriber work when several query updates occur together.
TanStack · Const
notifyManager batches TanStack Query updates and schedules notification callbacks. It supports framework-specific batching, custom notification handling, and configurable scheduling.
notifyManager coordinates TanStack Query notifications by batching updates and scheduling callbacks. Its batch method supports nesting and returns the callback's result, while scheduling defaults to setTimeout and can be customized for framework-specific rendering or test behavior.
const notifyManager: object;| Name | Type | Description |
|---|---|---|
batch callback | () => T | Callback executed within the batching scope. |
schedule callback | NotifyCallback | Notification callback queued for the next batch. |
fn | NotifyFunction | Framework-provided function that batches notifications. |
scheduler | Scheduler | Function used to schedule the next batch. |
notifyManager is an object exposing batch, schedule, setBatchNotifyFunction, setNotifyFunction, and setScheduler. batch returns the callback's result; schedule and configuration methods return void.
import { notifyManager } from '@tanstack/query-core'
const values: number[] = []
notifyManager.batch(() => {
values.push(1)
notifyManager.schedule(() => values.push(2))
})
console.log(values)Runs a synchronous update inside a batch and schedules another callback for the next notification batch.
Reduce redundant subscriber work when several query updates occur together.
Connect TanStack Query to a framework's own batching primitive.
Wrap notifications with a testing utility such as React.act.
Run notification batches in a microtask, animation frame, or delayed timeout.
notifyManager batches updates and schedules notification callbacks so multiple changes can be processed together. This reduces redundant subscriber work and, for framework adapters, can prevent multiple renders for one query update.
Follow-up: How can a framework integrate its own batching primitive? Use setBatchNotifyFunction with the framework's batch function so notifications are grouped into one tick.
batch executes updates within a batching scope, and nested scopes defer flushing until the outermost scope ends. It also passes the callback's return value through to the caller.
Follow-up: What happens to callbacks scheduled during a batch? They are queued for the next batch rather than executed immediately.
schedule queues a callback for the next batch. By default, the next batch is scheduled with setTimeout(callback, 0), but setScheduler can replace that timing function.
Follow-up: How would you schedule before the next frame? Configure setScheduler with requestAnimationFrame.
batchschedulesetBatchNotifyFunctionsetNotifyFunctionsetSchedulerdefaultScheduler