API Reference
useConvexMutation
Reference for the shared mutation composable.
useConvexMutation wraps a generated Convex mutation and tracks pending state and the latest error.
Import
Nuxt
const { mutate } = useConvexMutation(api.tasks.add)
Vue
import { useConvexMutation } from 'vue-convex'
Signature
function useConvexMutation<Mutation extends FunctionReference<'mutation'>>(
mutation: Mutation,
options?: {
optimisticUpdate?: OptimisticUpdate<FunctionArgs<Mutation>>
},
): {
mutate: (args: MaybeRefOrGetter<FunctionArgs<Mutation>>) => Promise<FunctionReturnType<Mutation>>
error: Ref<Error | null>
isPending: ComputedRef<boolean>
}
Parameters
| Parameter | Type | Meaning |
|---|---|---|
mutation | FunctionReference<'mutation'> | Generated Convex mutation reference |
options.optimisticUpdate | OptimisticUpdate<FunctionArgs<Mutation>> | Optional optimistic cache update forwarded to the Convex client |
Return value
| Field | Type | Meaning |
|---|---|---|
mutate | (args) => Promise<T> | Executes the mutation |
error | Ref<Error | null> | Latest mutation error |
isPending | ComputedRef<boolean> | true while one or more calls are in flight |
Behavior
- Requires a connected realtime client
- Accepts reactive args through
MaybeRefOrGetter - Supports optimistic updates through the underlying Convex client