Open History to see the last commit
1---
2id: NotifyManager
3title: NotifyManager
4redirect_from:
5 - framework/react/reference/notifyManager
6---
7β
8The `notifyManager` handles scheduling and batching callbacks in TanStack Query.
9β
10It exposes the following methods:
11β
12- [batch](#notifymanager-batch)
13- [batchCalls](#notifymanager-batchcalls)
14- [schedule](#notifymanager-schedule)
15- [setNotifyFunction](#notifymanager-setnotifyfunction)
16- [setBatchNotifyFunction](#notifymanager-setbatchnotifyfunction)
17- [setScheduler](#notifymanager-setscheduler)
18β
19## `notifyManager.batch`
20β
21`batch` can be used to batch all updates scheduled inside the passed callback.
22This is mainly used internally to optimize queryClient updating.
23β
24```ts
25function batch<T>(callback: () => T): T
26```
27β
28## `notifyManager.batchCalls`
29β
30`batchCalls` is a higher-order function that takes a callback and wraps it.
31All calls to the wrapped function schedule the callback to be run on the next batch.
32β
33```ts
34type BatchCallsCallback<T extends Array<unknown>> = (...args: T) => void
35β
36function batchCalls<T extends Array<unknown>>(
37 callback: BatchCallsCallback<T>,
38): BatchCallsCallback<T>
39```
40β
41## `notifyManager.schedule`
42β
43`schedule` schedules a function to be run on the next batch. By default, the batch is run
44with a setTimeout, but this can be configured.
45β
46```ts
47function schedule(callback: () => void): void
48```
49β
50## `notifyManager.setNotifyFunction`
51β
52`setNotifyFunction` overrides the notify function. This function is passed the
53callback when it should be executed. The default notifyFunction just calls it.
54β
55This can be used to for example wrap notifications with `React.act` while running tests:
56β
57```ts
58import { notifyManager } from '@tanstack/react-query'
59import { act } from 'react-dom/test-utils'
60β
61notifyManager.setNotifyFunction(act)
62```
63β
64## `notifyManager.setBatchNotifyFunction`
65β
66`setBatchNotifyFunction` sets the function to use for batched updates
67β
68If your framework supports a custom batching function, you can let TanStack Query know about it by calling notifyManager.setBatchNotifyFunction.
69β
70For example, this is how the batch function is set in solid-query:
71β
72```ts
73import { notifyManager } from '@tanstack/query-core'
74import { batch } from 'solid-js'
75β
76notifyManager.setBatchNotifyFunction(batch)
77```
78β
79## `notifyManager.setScheduler`
80β
81`setScheduler` configures a custom callback that should schedules when the next
82batch runs. The default behaviour is `setTimeout(callback, 0)`.
83β
84```ts
85import { notifyManager } from '@tanstack/react-query'
86β
87// Schedule batches in the next microtask
88notifyManager.setScheduler(queueMicrotask)
89β
90// Schedule batches before the next frame is rendered
91notifyManager.setScheduler(requestAnimationFrame)
92β
93// Schedule batches some time in the future
94notifyManager.setScheduler((cb) => setTimeout(cb, 10))
95```