Open History to see the last commit
1---
2id: notifyManager
3title: notifyManager
4redirect_from:
5 - reference/notifyManager
6 - framework/react/reference/notifyManager
7---
8β
9```ts
10const notifyManager: object;
11```
12β
13Defined in: [packages/query-core/src/notifyManager.ts:154](https://github.com/TanStack/query/blob/main/packages/query-core/src/notifyManager.ts#L154)
14β
15Handles scheduling and batching callbacks in TanStack Query.
16β
17## Type Declaration
18β
19### batch
20β
21```ts
22readonly batch: <T>(callback: () => T) => T;
23```
24β
25Batches all updates scheduled inside the passed callback.
26This is mainly used internally to optimize query client updating.
27Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
28The return value of `callback` is passed through.
29β
30#### Type Parameters
31β
32##### T
33β
34`T`
35β
36#### Parameters
37β
38##### callback
39β
40() => `T`
41β
42The function to run in the batch.
43β
44#### Returns
45β
46`T`
47β
48The return value of `callback`.
49β
50### batchCalls
51β
52```ts
53readonly batchCalls: <T>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
54```
55β
56All calls to the wrapped function will be batched.
57β
58#### Type Parameters
59β
60##### T
61β
62`T` *extends* `unknown`[]
63β
64#### Parameters
65β
66##### callback
67β
68`BatchCallsCallback`\<`T`\>
69β
70The function to wrap.
71β
72#### Returns
73β
74`BatchCallsCallback`\<`T`\>
75β
76A function that schedules a call to `callback` with the given arguments.
77β
78### schedule
79β
80```ts
81schedule: (callback: NotifyCallback) => void;
82```
83β
84Schedules a function to be run on the next batch.
85By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
86β
87#### Parameters
88β
89##### callback
90β
91`NotifyCallback`
92β
93#### Returns
94β
95`void`
96β
97### setBatchNotifyFunction
98β
99```ts
100readonly setBatchNotifyFunction: (fn: BatchNotifyFunction) => void;
101```
102β
103Use this method to set a custom function to batch notifications together into a single tick.
104Framework adapters use this to plug in their own batching primitive, so that a single query
105update only triggers one re-render instead of one per subscriber.
106β
107#### Parameters
108β
109##### fn
110β
111`BatchNotifyFunction`
112β
113Receives a function that runs a batch of notifications and must call it.
114β
115#### Returns
116β
117`void`
118β
119#### Example
120β
121```ts
122import { notifyManager } from '@tanstack/query-core'
123import { batch } from 'solid-js'
124β
125notifyManager.setBatchNotifyFunction(batch)
126```
127β
128### setNotifyFunction
129β
130```ts
131readonly setNotifyFunction: (fn: NotifyFunction) => void;
132```
133β
134Use this method to set a custom notify function.
135This can be used to for example wrap notifications with `React.act` while running tests.
136β
137#### Parameters
138β
139##### fn
140β
141`NotifyFunction`
142β
143Receives each notification callback and must call it.
144β
145#### Returns
146β
147`void`
148β
149### setScheduler
150β
151```ts
152readonly setScheduler: (fn: ScheduleFunction) => void;
153```
154β
155Configures a custom callback that schedules when the next batch runs.
156The default behavior is `setTimeout(callback, 0)`.
157β
158#### Parameters
159β
160##### fn
161β
162`ScheduleFunction`
163β
164Receives a callback that runs the next batch, and schedules it.
165β
166#### Returns
167β
168`void`
169β
170#### Example
171β
172```ts
173import { notifyManager } from '@tanstack/query-core'
174β
175// Schedule batches in the next microtask
176notifyManager.setScheduler(queueMicrotask)
177β
178// Schedule batches before the next frame is rendered
179notifyManager.setScheduler(requestAnimationFrame)
180β
181// Schedule batches some time in the future
182notifyManager.setScheduler((cb) => setTimeout(cb, 10))
183```