Open History to see the last commit
1// The typical app, plus debounced mutations through the React adapter.
2import { debounceStrategy } from '@tanstack/db'
3import { usePacedMutations } from '@tanstack/react-db'
4import { todos } from './app.js'
5
6export * from './app.js'
7
8export function useRenameTodo() {
9 return usePacedMutations({
10 onMutate: ({ id, title }) =>
11 todos.update(id, (draft) => {
12 draft.title = title
13 }),
14 mutationFn: ({ transaction }) =>
15 fetch(`/api/todos`, {
16 method: `PATCH`,
17 body: JSON.stringify(transaction.mutations.map((m) => m.modified)),
18 }),
19 strategy: debounceStrategy({ wait: 500 }),
20 })
21}