Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

LocalOnlyCollectionUtils.md

62 lines1.4 KB

1---
2id: LocalOnlyCollectionUtils
3title: LocalOnlyCollectionUtils
4---
5​
6# Interface: LocalOnlyCollectionUtils
7​
8Defined in: [packages/db/src/local-only.ts:40](https://github.com/TanStack/db/blob/main/packages/db/src/local-only.ts#L40)
9​
10Local-only 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-only.ts:58](https://github.com/TanStack/db/blob/main/packages/db/src/local-only.ts#L58)
31​
32Accepts mutations from a transaction that belong to this collection and persists them.
33This should be called in your transaction's mutationFn to persist local-only 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 localData = createCollection(localOnlyCollectionOptions({...}))
53​
54const tx = createTransaction({
55 mutationFn: async ({ transaction }) => {
56 // Make API call first
57 await api.save(...)
58 // Then persist local-only mutations after success
59 localData.utils.acceptMutations(transaction)
60 }
61})
62```