Capítulo 60 de 80

Chapter 60: NotifyManager

Core Idea

notifyManager batches and schedules internal update notifications — its main external hook is setBatchNotifyFunction, the way non-React framework adapters (e.g. solid-query calling SolidJS's batch) tell TanStack Query how to batch re-renders for their own reactivity system.

Key Concepts

  • batch(callback): runs callback, batching every update scheduled inside it — mainly internal, used to coalesce QueryClient updates.
  • batchCalls(callback): wraps a callback so every invocation schedules it to run on the next batch instead of immediately.
  • schedule(callback): queues a callback for the next batch — runs via setTimeout by default, configurable through setScheduler.
  • setNotifyFunction(fn): overrides how an individual notification is delivered — e.g. wrapping calls in React's act() during tests.
  • setBatchNotifyFunction(fn): the framework-integration hook — tells the library to use a specific batching function (e.g. solid-js's batch) instead of its own default, so updates coalesce correctly within that framework's reactivity model.
  • setScheduler(fn): replaces when the next batch runs — default is setTimeout(cb, 0); alternatives include queueMicrotask (next microtask) or requestAnimationFrame (before next paint).

Code Examples

// Framework-adapter batching integration (as solid-query does)
import { batch } from 'solid-js'
notifyManager.setBatchNotifyFunction(batch)

// Test-friendly notification wrapping
notifyManager.setNotifyFunction(act)
  • What it demonstrates: the two most common external uses — framework-specific batching, and test-safe notification wrapping.

Key Takeaways

  1. Most React apps never touch this directly — it matters mainly for non-React framework adapters or testing infrastructure.
  2. setBatchNotifyFunction is the integration point a new framework adapter needs to implement correctly, not batch/batchCalls/schedule directly.

Connects To

  • Render Optimizations: the update-notification pipeline this manager schedules.
  • Testing: setNotifyFunction(act) for wrapping test-time notifications.