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