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

app-optimistic-action.js

13 lines381 Bytes

1// The typical app, plus an optimistic action.
2import { createOptimisticAction } from '@tanstack/db'
3import { todos } from './app.js'
4​
5export * from './app.js'
6​
7export const completeTodo = createOptimisticAction({
8 onMutate: (id) =>
9 todos.update(id, (draft) => {
10 draft.done = true
11 }),
12 mutationFn: (id) => fetch(`/api/todos/${id}/complete`, { method: `POST` }),
13})