
const [mutate,{ status, isIdle, isLoading, isSuccess, isError, data, error, reset },] = useMutation(mutationFn, {onMutate,onSuccess,onError,onSettled,throwOnError,useErrorBoundary,})const promise = mutate(variables, {onSuccess,onSettled,onError,throwOnError,})
Options
mutationFn: (variables: TVariables) => Promise<TData>variables is an object that mutate will pass to your mutationFnonMutate: (variables: TVariables) => Promise<TContext | void> | TContext | voidonError and onSettled functions in the event of a mutation failure and can be useful for rolling back optimistic updates.onSuccess: (data: TData, variables: TVariables, context: TContext) => Promise<void> | voidmutate-level onSuccess handler (if it is defined)onError: (err: TError, variables: TVariables, context?: TContext) => Promise<void> | voidmutate-level onError handler (if it is defined)onSettled: (data: TData, error: TError, variables: TVariables, context?: TContext) => Promise<void> | voidmutate-level onSettled handler (if it is defined)throwOnErrorfalsetrue if failed mutations should re-throw errors from the mutation function to the mutate function.useErrorBoundaryuseErrorBoundary value, which is falseReturns
mutate: (variables: TVariables, { onSuccess, onSettled, onError, throwOnError }) => Promise<TData>variables: TVariablesmutationFn.useMutation hook.useMutation-level options.status: stringidle initial status prior to the mutation function executing.loading if the mutation is currently executing.error if the last mutation attempt resulted in an error.success if the last mutation attempt was successful.isIdle, isLoading, isSuccess, isError: boolean variables derived from statusdata: undefined | unknownundefinederror: null | TErrorreset: () => voidThe latest TanStack news, articles, and resources, sent to your inbox.