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