Open History to see the last commit
1---
2id: LocalStorageCollectionUtils
3title: LocalStorageCollectionUtils
4---
5
6Defined in: [packages/db/src/local-storage.ts:102](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L102)
7
8LocalStorage collection utilities type
9
10## Extends
11
12- [`UtilsRecord`](../type-aliases/UtilsRecord.md)
13
14## Indexable
15
16```ts
17[key: string]: any
18```
19
20## Properties
21
22### acceptMutations()
23
24```ts
25acceptMutations: (transaction) => Promise<void>;
26```
27
28Defined in: [packages/db/src/local-storage.ts:122](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L122)
29
30Accepts mutations from a transaction that belong to this collection and persists them to localStorage.
31Call this in your transaction's mutationFn. Its persistence receipt follows the storage write even
32if the returned Promise is not awaited. Await it when later mutationFn work depends on the write.
33
34#### Parameters
35
36##### transaction
37
38The transaction containing mutations to accept
39
40###### mutations
41
42[`PendingMutation`](PendingMutation.md)\<`Record`\<`string`, `unknown`\>, [`OperationType`](../type-aliases/OperationType.md), [`Collection`](Collection.md)\<`Record`\<`string`, `unknown`\>, `any`, `any`, `any`, `any`\>\>[]
43
44#### Returns
45
46`Promise`\<`void`\>
47
48#### Example
49
50```ts
51const localSettings = createCollection(localStorageCollectionOptions({...}))
52
53const tx = createTransaction({
54 mutationFn: async ({ transaction }) => {
55 // Make API call first
56 await api.save(...)
57 // Then persist local-storage mutations after success
58 await localSettings.utils.acceptMutations(transaction)
59 }
60})
61```
62
63***
64
65### clearStorage
66
67```ts
68clearStorage: ClearStorageFn;
69```
70
71Defined in: [packages/db/src/local-storage.ts:103](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L103)
72
73***
74
75### getStorageSize
76
77```ts
78getStorageSize: GetStorageSizeFn;
79```
80
81Defined in: [packages/db/src/local-storage.ts:104](https://github.com/TanStack/db/blob/main/packages/db/src/local-storage.ts#L104)