const {
data,
error,
isError,
isIdle,
isPending,
isPaused,
isSuccess,
failureCount,
failureReason,
mutate,
mutateAsync,
reset,
status,
submittedAt,
variables,
} = useMutation(
{
mutationFn,
gcTime,
meta,
mutationKey,
networkMode,
onError,
onMutate,
onSettled,
onSuccess,
retry,
retryDelay,
scope,
throwOnError,
},
queryClient,
)
mutate(variables, {
onError,
onSettled,
onSuccess,
})Parameter1 (Options)
mutationFn: (variables: TVariables, context: MutationFunctionContext) => Promise<TData>
gcTime: number | Infinity
mutationKey: unknown[]
networkMode: 'online' | 'always' | 'offlineFirst'
onMutate: (variables: TVariables, context: MutationFunctionContext) => Promise<TOnMutateResult | void> | TOnMutateResult | void
onSuccess: (data: TData, variables: TVariables, onMutateResult: TOnMutateResult | undefined, context: MutationFunctionContext) => Promise<unknown> | unknown
onError: (err: TError, variables: TVariables, onMutateResult: TOnMutateResult | undefined, context: MutationFunctionContext) => Promise<unknown> | unknown
onSettled: (data: TData, error: TError, variables: TVariables, onMutateResult: TOnMutateResult | undefined, context: MutationFunctionContext) => Promise<unknown> | unknown
retry: boolean | number | (failureCount: number, error: TError) => boolean
retryDelay: number | (retryAttempt: number, error: TError) => number
scope: { id: string }
throwOnError: undefined | boolean | (error: TError) => boolean
meta: Record<string, unknown>
Optional
If set, stores additional information on the mutation cache entry that can be used as needed. It will be accessible wherever the mutation is available (eg. onError, onSuccess functions of the MutationCache).
Parameter2 (QueryClient)
queryClient?: QueryClient
Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
Returns
mutate: (variables: TVariables, { onSuccess, onSettled, onError }) => void
mutateAsync: (variables: TVariables, { onSuccess, onSettled, onError }) => Promise<TData>
status: MutationStatus
isIdle, isPending, isSuccess, isError: boolean variables derived from status
isPaused: boolean
data: undefined | unknown
error: null | TError
reset: () => void
failureCount: number
failureReason: null | TError
submittedAt: number
variables: undefined | TVariables