MCPcopy Create free account
hub / github.com/TanStack/db / configMutationFn

Function configMutationFn

examples/react/todo/src/routes/query.tsx:35–61  ·  view source on GitHub ↗
({
    transaction,
  }: {
    transaction: Transaction
  })

Source from the content-addressed store, hash-verified

33
34 // Query collections automatically refetch after handler completes
35 const configMutationFn = async ({
36 transaction,
37 }: {
38 transaction: Transaction
39 }) => {
40 // Handle inserts
41 const inserts = transaction.mutations.filter((m) => m.type === `insert`)
42 await Promise.all(
43 inserts.map(async (mutation) => {
44 await api.config.create(mutation.modified)
45 }),
46 )
47
48 // Handle updates
49 const updates = transaction.mutations.filter((m) => m.type === `update`)
50 await Promise.all(
51 updates.map(async (mutation) => {
52 if (!(`id` in mutation.original)) {
53 throw new Error(`Original config not found for update`)
54 }
55 await api.config.update(mutation.original.id, mutation.changes)
56 }),
57 )
58
59 // Trigger refetch to get confirmed server state
60 await queryConfigCollection.utils.refetch()
61 }
62
63 return (
64 <TodoApp

Callers

nothing calls this directly

Calls 3

filterMethod · 0.80
mapMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected