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:144](https://github.com/TanStack/query/blob/main/packages/query-core/src/notifyManager.ts#L144)
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β
39#### Returns
40β
41`T`
42β
43### batchCalls()
44β
45```ts
46readonly batchCalls: <T>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
47```
48β
49All calls to the wrapped function will be batched.
50β
51#### Type Parameters
52β
53##### T
54β
55`T` *extends* `unknown`[]
56β
57#### Parameters
58β
59##### callback
60β
61`BatchCallsCallback`\<`T`\>
62β
63#### Returns
64β
65`BatchCallsCallback`\<`T`\>
66β
67### schedule()
68β
69```ts
70schedule: (callback: NotifyCallback) => void;
71```
72β
73Schedules a function to be run on the next batch.
74By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
75β
76#### Parameters
77β
78##### callback
79β
80`NotifyCallback`
81β
82#### Returns
83β
84`void`
85β
86### setBatchNotifyFunction()
87β
88```ts
89readonly setBatchNotifyFunction: (fn: BatchNotifyFunction) => void;
90```
91β
92Use this method to set a custom function to batch notifications together into a single tick.
93Framework adapters use this to plug in their own batching primitive, so that a single query
94update only triggers one re-render instead of one per subscriber.
95β
96#### Parameters
97β
98##### fn
99β
100`BatchNotifyFunction`
101β
102#### Returns
103β
104`void`
105β
106#### Example
107β
108```ts
109import { notifyManager } from '@tanstack/query-core'
110import { batch } from 'solid-js'
111β
112notifyManager.setBatchNotifyFunction(batch)
113```
114β
115### setNotifyFunction()
116β
117```ts
118readonly setNotifyFunction: (fn: NotifyFunction) => void;
119```
120β
121Use this method to set a custom notify function.
122This can be used to for example wrap notifications with `React.act` while running tests.
123β
124#### Parameters
125β
126##### fn
127β
128`NotifyFunction`
129β
130#### Returns
131β
132`void`
133β
134### setScheduler()
135β
136```ts
137readonly setScheduler: (fn: ScheduleFunction) => void;
138```
139β
140Configures a custom callback that schedules when the next batch runs.
141The default behavior is `setTimeout(callback, 0)`.
142β
143#### Parameters
144β
145##### fn
146β
147`ScheduleFunction`
148β
149#### Returns
150β
151`void`
152β
153#### Example
154β
155```ts
156import { notifyManager } from '@tanstack/query-core'
157β
158// Schedule batches in the next microtask
159notifyManager.setScheduler(queueMicrotask)
160β
161// Schedule batches before the next frame is rendered
162notifyManager.setScheduler(requestAnimationFrame)
163β
164// Schedule batches some time in the future
165notifyManager.setScheduler((cb) => setTimeout(cb, 10))
166```