Convex mutation client.
Convex mutation function reference.
A typed mutation function with optional optimistic update support.
Use this when you need a typed mutation helper outside a
BaseConvexNode. Mutations are imperative calls and do not emit
Retree changes by themselves. Pair with withOptimisticUpdate to update a
query node immediately, or wait for a subscribed query to emit the server
value.
const toggleCompleted = createRetreeConvexMutation(
client,
api.tasks.toggleCompleted
);
await toggleCompleted(
{ taskId },
{
withOptimisticUpdate: (ctx) => {
tasks.optimisticUpdate({
ctx,
apply(items) {
const task = items.find((item) => item._id === taskId);
if (task) task.isCompleted = !task.isCompleted;
},
});
},
}
);
Create a typed Retree Convex mutation function from a Convex client and mutation reference.