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

LocalOnlyCollectionUtils.md

60 lines1.4 KB

1---
2id: LocalOnlyCollectionUtils
3title: LocalOnlyCollectionUtils
4---
5​
6Defined in: [packages/db/src/local-only.ts:42](https://github.com/TanStack/db/blob/main/packages/db/src/local-only.ts#L42)
7​
8Local-only 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) => void;
26```
27​
28Defined in: [packages/db/src/local-only.ts:60](https://github.com/TanStack/db/blob/main/packages/db/src/local-only.ts#L60)
29​
30Accepts mutations from a transaction that belong to this collection and persists them.
31This should be called in your transaction's mutationFn to persist local-only data.
32​
33#### Parameters
34​
35##### transaction
36​
37The transaction containing mutations to accept
38​
39###### mutations
40​
41[`PendingMutation`](PendingMutation.md)\<`Record`\<`string`, `unknown`\>, [`OperationType`](../type-aliases/OperationType.md), [`Collection`](Collection.md)\<`Record`\<`string`, `unknown`\>, `any`, `any`, `any`, `any`\>\>[]
42​
43#### Returns
44​
45`void`
46​
47#### Example
48​
49```ts
50const localData = createCollection(localOnlyCollectionOptions({...}))
51​
52const tx = createTransaction({
53 mutationFn: async ({ transaction }) => {
54 // Make API call first
55 await api.save(...)
56 // Then persist local-only mutations after success
57 localData.utils.acceptMutations(transaction)
58 }
59})
60```