API reference · generated from source
Function: createRetreeConvexMutation()#
function createRetreeConvexMutation<Mutation>(client, mutation): RetreeConvexMutation<Mutation>;Defined in: retree-convex/src/mutations.ts:50
Create a typed Retree Convex mutation function from a Convex client and mutation reference.
Type Parameters#
| Type Parameter |
|---|
Mutation extends MutationReference |
Parameters#
| Parameter | Type | Description |
|---|---|---|
client | IConvexMutationClient | Convex mutation client. |
mutation | Mutation | Convex mutation function reference. |
Returns#
RetreeConvexMutation<Mutation>
A typed mutation function with optional optimistic update support.
Remarks#
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.
Example#
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;
},
});
},
}
);