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