Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TanStack · Const

notifyManager

notifyManager batches TanStack Query updates and schedules notification callbacks. It supports framework-specific batching, custom notification handling, and configurable scheduling.

How it works

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.

Syntax

const notifyManager: object;

Parameters

NameTypeDescription
batch callback() => TCallback executed within the batching scope.
schedule callbackNotifyCallbackNotification callback queued for the next batch.
fnNotifyFunctionFramework-provided function that batches notifications.
schedulerSchedulerFunction used to schedule the next batch.

Returns

notifyManager is an object exposing batch, schedule, setBatchNotifyFunction, setNotifyFunction, and setScheduler. batch returns the callback's result; schedule and configuration methods return void.

Key points

  • notifyManager is the core utility for coordinating callback scheduling and notification batching.
  • batch groups updates performed within its callback.
  • batch preserves and returns the callback's result.
  • A configured batch notification function groups every callback invocation it wraps.
  • setBatchNotifyFunction lets framework integrations provide their native batching mechanism.
  • schedule defers a callback until the next notification batch.
  • setScheduler changes the function responsible for starting the next batch.

Common mistakes

  • Nested batches do not flush independently; queued work waits until the outermost batch completes.
  • A custom notify function must invoke every callback it receives.
  • Changing the scheduler changes when the next batch runs; the default is a zero-delay timeout.

Example: Batch and schedule notifications

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.

When to use it

Batch query updates

Reduce redundant subscriber work when several query updates occur together.

Framework rendering integration

Connect TanStack Query to a framework's own batching primitive.

Test-safe notifications

Wrap notifications with a testing utility such as React.act.

Control notification timing

Run notification batches in a microtask, animation frame, or delayed timeout.

Interview questions

QWhy does TanStack Query use notifyManager?

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.

QWhat are the important semantics of batch?

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.

QHow can notification timing be customized?

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.

  • batch
  • schedule
  • setBatchNotifyFunction
  • setNotifyFunction
  • setScheduler
  • defaultScheduler

Source: notifyManager | TanStack Query React Docs. Checked 2026-10-16.