API Documentation / @pinia/colada / useMutation
Function: useMutation()
ts
function useMutation<TResult, TVars, TError, TContext>(options): UseMutationReturn<TResult, TVars, TError>
Setups a mutation.
Type Parameters
TResult
TResult
TVars
TVars
= void
TError
TError
= { custom
: Error
; }
TContext
TContext
extends Record
<any
, any
> = _EmptyObject
Parameters
options
UseMutationOptions
<TResult
, TVars
, TError
, TContext
>
Options to create the mutation
Returns
UseMutationReturn
<TResult
, TVars
, TError
>
Example
ts
const queryCache = useQueryCache()
const { mutate, status, error } = useMutation({
mutation: (id: number) => fetch(`/api/todos/${id}`),
onSuccess() {
queryCache.invalidateQueries('todos')
},
})