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:822](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L822)
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:827](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L827)
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:860](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L860)
43
44**`Internal`**
45
46Optional limit to include in loadSubset for query-specific cache keys.
47
48***
49
50### onLoadSubsetResult()?
51
52```ts
53optional onLoadSubsetResult: (result) => void;
54```
55
56Defined in: [packages/db/src/types.ts:866](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L866)
57
58**`Internal`**
59
60Callback that receives the loadSubset result (Promise or true) from requestSnapshot.
61Allows the caller to directly track the loading promise for isReady status.
62
63#### Parameters
64
65##### result
66
67`true` | `Promise`\<`void`\>
68
69#### Returns
70
71`void`
72
73***
74
75### onStatusChange()?
76
77```ts
78optional onStatusChange: (event) => void;
79```
80
81Defined in: [packages/db/src/types.ts:850](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L850)
82
83**`Internal`**
84
85Listener for subscription status changes.
86Registered BEFORE any snapshot is requested, ensuring no status transitions are missed.
87
88#### Parameters
89
90##### event
91
92[`SubscriptionStatusChangeEvent`](SubscriptionStatusChangeEvent.md)
93
94#### Returns
95
96`void`
97
98***
99
100### orderBy?
101
102```ts
103optional orderBy: OrderBy;
104```
105
106Defined in: [packages/db/src/types.ts:855](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L855)
107
108**`Internal`**
109
110Optional orderBy to include in loadSubset for query-specific cache keys.
111
112***
113
114### where()?
115
116```ts
117optional where: (row) => any;
118```
119
120Defined in: [packages/db/src/types.ts:842](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L842)
121
122Callback function for filtering changes using a row proxy.
123The callback receives a proxy object that records property access,
124allowing you to use query builder functions like `eq`, `gt`, etc.
125
126#### Parameters
127
128##### row
129
130`SingleRowRefProxy`\<[`WithVirtualProps`](../type-aliases/WithVirtualProps.md)\<`T`, `TKey`\>\>
131
132#### Returns
133
134`any`
135
136#### Example
137
138```ts
139import { eq } from "@tanstack/db"
140
141collection.subscribeChanges(callback, {
142 where: (row) => eq(row.status, "active")
143})
144```
145
146***
147
148### whereExpression?
149
150```ts
151optional whereExpression: BasicExpression<boolean>;
152```
153
154Defined in: [packages/db/src/types.ts:844](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L844)
155
156Pre-compiled expression for filtering changes