const {
data,
error,
isError,
isIdle,
isLoading,
isPaused,
isSuccess,
failureCount,
failureReason,
mutate,
mutateAsync,
reset,
status,
} = useMutation({
mutationFn,
cacheTime,
mutationKey,
networkMode,
onError,
onMutate,
onSettled,
onSuccess,
retry,
retryDelay,
useErrorBoundary,
meta,
})
mutate(variables, {
onError,
onSettled,
onSuccess,
})Options
mutationFn: (variables: TVariables) => Promise<TData>
cacheTime: number | Infinity
mutationKey: unknown[]
networkMode: 'online' | 'always' | 'offlineFirst'
onMutate: (variables: TVariables) => Promise<TContext | void> | TContext | void
onSuccess: (data: TData, variables: TVariables, context?: TContext) => Promise<unknown> | unknown
onError: (err: TError, variables: TVariables, context?: TContext) => Promise<unknown> | unknown
onSettled: (data: TData, error: TError, variables: TVariables, context?: TContext) => Promise<unknown> | unknown
retry: boolean | number | (failureCount: number, error: TError) => boolean
retryDelay: number | (retryAttempt: number, error: TError) => number
useErrorBoundary: undefined | boolean | (error: TError) => boolean
meta: Record<string, unknown>
context?: React.Context<QueryClient | undefined>
Use this to use a custom React Query context. Otherwise, defaultContext will be used.
Returns
mutate: (variables: TVariables, { onSuccess, onSettled, onError }) => void
mutateAsync: (variables: TVariables, { onSuccess, onSettled, onError }) => Promise<TData>
status: string
isIdle, isLoading, isSuccess, isError: boolean variables derived from status
isPaused: boolean
data: undefined | unknown
error: null | TError
reset: () => void
failureCount: number
failureReason: null | TError