Open History to see the last commit
1---
2id: SubscribeChangesOptions
3title: SubscribeChangesOptions
4---
5
6# Interface: SubscribeChangesOptions\<T, TKey\>
7
8Defined in: [packages/db/src/types.ts:892](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L892)
9
10Options for subscribing to collection changes
11
12## Type Parameters
13
14### T
15
16`T` *extends* `object` = `Record`\<`string`, `unknown`\>
17
18### TKey
19
20`TKey` *extends* `string` \| `number` = `string` \| `number`
21
22## Properties
23
24### includeInitialState?
25
26```ts
27optional includeInitialState: boolean;
28```
29
30Defined in: [packages/db/src/types.ts:897](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L897)
31
32Whether to include the current state as initial changes
33
34***
35
36### limit?
37
38```ts
39optional limit: number;
40```
41
42Defined in: [packages/db/src/types.ts:930](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L930)
43
44**`Internal`**
45
46Optional limit to include in loadSubset for query-specific cache keys.
47
48***
49
50### onLoadSubsetError()?
51
52```ts
53optional onLoadSubsetError: (event) => void;
54```
55
56Defined in: [packages/db/src/types.ts:938](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L938)
57
58**`Internal`**
59
60Receives subset-load failures scoped to this subscription.
61
62#### Parameters
63
64##### event
65
66[`SubscriptionLoadSubsetErrorEvent`](SubscriptionLoadSubsetErrorEvent.md)
67
68#### Returns
69
70`void`
71
72***
73
74### onLoadSubsetResult()?
75
76```ts
77optional onLoadSubsetResult: (result) => void;
78```
79
80Defined in: [packages/db/src/types.ts:936](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L936)
81
82**`Internal`**
83
84Callback that receives the loadSubset result (Promise or true) from requestSnapshot.
85Allows the caller to directly track the loading promise for isReady status.
86
87#### Parameters
88
89##### result
90
91`true` | `Promise`\<`void`\>
92
93#### Returns
94
95`void`
96
97***
98
99### onStatusChange()?
100
101```ts
102optional onStatusChange: (event) => void;
103```
104
105Defined in: [packages/db/src/types.ts:920](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L920)
106
107**`Internal`**
108
109Listener for subscription status changes.
110Registered BEFORE any snapshot is requested, ensuring no status transitions are missed.
111
112#### Parameters
113
114##### event
115
116[`SubscriptionStatusChangeEvent`](SubscriptionStatusChangeEvent.md)
117
118#### Returns
119
120`void`
121
122***
123
124### orderBy?
125
126```ts
127optional orderBy: OrderBy;
128```
129
130Defined in: [packages/db/src/types.ts:925](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L925)
131
132**`Internal`**
133
134Optional orderBy to include in loadSubset for query-specific cache keys.
135
136***
137
138### where()?
139
140```ts
141optional where: (row) => any;
142```
143
144Defined in: [packages/db/src/types.ts:912](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L912)
145
146Callback function for filtering changes using a row proxy.
147The callback receives a proxy object that records property access,
148allowing you to use query builder functions like `eq`, `gt`, etc.
149
150#### Parameters
151
152##### row
153
154`SingleRowRefProxy`\<[`WithVirtualProps`](../type-aliases/WithVirtualProps.md)\<`T`, `TKey`\>\>
155
156#### Returns
157
158`any`
159
160#### Example
161
162```ts
163import { eq } from "@tanstack/db"
164
165collection.subscribeChanges(callback, {
166 where: (row) => eq(row.status, "active")
167})
168```
169
170***
171
172### whereExpression?
173
174```ts
175optional whereExpression: BasicExpression<boolean>;
176```
177
178Defined in: [packages/db/src/types.ts:914](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L914)
179
180Pre-compiled expression for filtering changes