Open History to see the last commit
1---
2id: LocalStorageCollectionConfig
3title: LocalStorageCollectionConfig
4---
5
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7
8# Interface: LocalStorageCollectionConfig\<TExplicit, TSchema, TFallback\>
9
10Defined in: [packages/db/src/local-storage.ts:61](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L61)
11
12Configuration interface for localStorage collection options
13
14## Remarks
15
16Type resolution follows a priority order:
171. If you provide an explicit type via generic parameter, it will be used
182. If no explicit type is provided but a schema is, the schema's output type will be inferred
193. If neither explicit type nor schema is provided, the fallback type will be used
20
21You should provide EITHER an explicit type OR a schema, but not both, as they would conflict.
22
23## Type Parameters
24
25• **TExplicit** = `unknown`
26
27The explicit type of items in the collection (highest priority)
28
29• **TSchema** *extends* `StandardSchemaV1` = `never`
30
31The schema type for validation and type inference (second priority)
32
33• **TFallback** *extends* `object` = `Record`\<`string`, `unknown`\>
34
35The fallback type if no explicit or schema type is provided
36
37## Properties
38
39### getKey()
40
41```ts
42getKey: (item) => string | number;
43```
44
45Defined in: [packages/db/src/local-storage.ts:88](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L88)
46
47#### Parameters
48
49##### item
50
51[`ResolveType`](../../type-aliases/resolvetype.md)
52
53#### Returns
54
55`string` \| `number`
56
57***
58
59### id?
60
61```ts
62optional id: string;
63```
64
65Defined in: [packages/db/src/local-storage.ts:86](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L86)
66
67Collection identifier (defaults to "local-collection:{storageKey}" if not provided)
68
69***
70
71### onDelete()?
72
73```ts
74optional onDelete: (params) => Promise<any>;
75```
76
77Defined in: [packages/db/src/local-storage.ts:114](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L114)
78
79Optional asynchronous handler function called before a delete operation
80
81#### Parameters
82
83##### params
84
85[`DeleteMutationFnParams`](../../type-aliases/deletemutationfnparams.md)\<[`ResolveType`](../../type-aliases/resolvetype.md)\<`TExplicit`, `TSchema`, `TFallback`\>\>
86
87Object containing transaction and collection information
88
89#### Returns
90
91`Promise`\<`any`\>
92
93Promise resolving to any value
94
95***
96
97### onInsert()?
98
99```ts
100optional onInsert: (params) => Promise<any>;
101```
102
103Defined in: [packages/db/src/local-storage.ts:96](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L96)
104
105Optional asynchronous handler function called before an insert operation
106
107#### Parameters
108
109##### params
110
111[`InsertMutationFnParams`](../../type-aliases/insertmutationfnparams.md)\<[`ResolveType`](../../type-aliases/resolvetype.md)\<`TExplicit`, `TSchema`, `TFallback`\>\>
112
113Object containing transaction and collection information
114
115#### Returns
116
117`Promise`\<`any`\>
118
119Promise resolving to any value
120
121***
122
123### onUpdate()?
124
125```ts
126optional onUpdate: (params) => Promise<any>;
127```
128
129Defined in: [packages/db/src/local-storage.ts:105](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L105)
130
131Optional asynchronous handler function called before an update operation
132
133#### Parameters
134
135##### params
136
137[`UpdateMutationFnParams`](../../type-aliases/updatemutationfnparams.md)\<[`ResolveType`](../../type-aliases/resolvetype.md)\<`TExplicit`, `TSchema`, `TFallback`\>\>
138
139Object containing transaction and collection information
140
141#### Returns
142
143`Promise`\<`any`\>
144
145Promise resolving to any value
146
147***
148
149### schema?
150
151```ts
152optional schema: TSchema;
153```
154
155Defined in: [packages/db/src/local-storage.ts:87](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L87)
156
157***
158
159### storage?
160
161```ts
162optional storage: StorageApi;
163```
164
165Defined in: [packages/db/src/local-storage.ts:75](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L75)
166
167Storage API to use (defaults to window.localStorage)
168Can be any object that implements the Storage interface (e.g., sessionStorage)
169
170***
171
172### storageEventApi?
173
174```ts
175optional storageEventApi: StorageEventApi;
176```
177
178Defined in: [packages/db/src/local-storage.ts:81](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L81)
179
180Storage event API to use for cross-tab synchronization (defaults to window)
181Can be any object that implements addEventListener/removeEventListener for storage events
182
183***
184
185### storageKey
186
187```ts
188storageKey: string;
189```
190
191Defined in: [packages/db/src/local-storage.ts:69](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L69)
192
193The key to use for storing the collection data in localStorage/sessionStorage
194
195***
196
197### sync?
198
199```ts
200optional sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, string | number>;
201```
202
203Defined in: [packages/db/src/local-storage.ts:89](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L89)