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