Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/src/pages/reference/useMutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ mutate(variables, {
- This function will fire before the mutation function is fired and is passed the same variables the mutation function would receive
- Useful to perform optimistic updates to a resource in hopes that the mutation succeeds
- The value returned from this function will be passed to both the `onError` 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> | void`
- `onSuccess: (data: TData, variables: TVariables, context?: TContext) => Promise<unknown> | void`
- Optional
- This function will fire when the mutation is successful and will be passed the mutation's result.
- If a promise is returned, it will be awaited and resolved before proceeding
- `onError: (err: TError, variables: TVariables, context?: TContext) => Promise<void> | void`
- `onError: (err: TError, variables: TVariables, context?: TContext) => Promise<unknown> | void`
- Optional
- This function will fire if the mutation encounters an error and will be passed the error.
- If a promise is returned, it will be awaited and resolved before proceeding
- `onSettled: (data: TData, error: TError, variables: TVariables, context?: TContext) => Promise<void> | void`
- `onSettled: (data: TData, error: TError, variables: TVariables, context?: TContext) => Promise<unknown> | void`
- Optional
- This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error
- If a promise is returned, it will be awaited and resolved before proceeding
Expand Down
24 changes: 16 additions & 8 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ export interface FetchInfiniteQueryOptions<
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
> extends FetchQueryOptions<TQueryFnData, TError, InfiniteData<TData>, TQueryKey> {}
>
extends FetchQueryOptions<
TQueryFnData,
TError,
InfiniteData<TData>,
TQueryKey
> {}

export interface ResultOptions {
throwOnError?: boolean
Expand Down Expand Up @@ -474,23 +480,25 @@ export interface MutationOptions<
mutationFn?: MutationFunction<TData, TVariables>
mutationKey?: MutationKey
variables?: TVariables
onMutate?: (variables: TVariables) => Promise<TContext> | Promise<undefined> | TContext | undefined
onMutate?: (
variables: TVariables
) => Promise<TContext> | Promise<undefined> | TContext | undefined
onSuccess?: (
data: TData,
variables: TVariables,
context: TContext
) => Promise<void> | void
) => Promise<unknown> | void
onError?: (
error: TError,
variables: TVariables,
context: TContext | undefined
) => Promise<void> | void
) => Promise<unknown> | void
onSettled?: (
data: TData | undefined,
error: TError | null,
variables: TVariables,
context: TContext | undefined
) => Promise<void> | void
) => Promise<unknown> | void
retry?: RetryValue<TError>
retryDelay?: RetryDelayValue<TError>
_defaulted?: boolean
Expand All @@ -515,18 +523,18 @@ export interface MutateOptions<
data: TData,
variables: TVariables,
context: TContext
) => Promise<void> | void
) => Promise<unknown> | void
onError?: (
error: TError,
variables: TVariables,
context: TContext | undefined
) => Promise<void> | void
) => Promise<unknown> | void
onSettled?: (
data: TData | undefined,
error: TError | null,
variables: TVariables,
context: TContext | undefined
) => Promise<void> | void
) => Promise<unknown> | void
}

export type MutateFunction<
Expand Down
10 changes: 6 additions & 4 deletions src/react/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,25 @@ export interface UseMutationOptions<
TContext = unknown
> {
mutationKey?: MutationKey
onMutate?: (variables: TVariables) => Promise<TContext> | Promise<undefined> | TContext | undefined
onMutate?: (
variables: TVariables
) => Promise<TContext> | Promise<undefined> | TContext | undefined
onSuccess?: (
data: TData,
variables: TVariables,
context: TContext | undefined
) => Promise<void> | void
) => Promise<unknown> | void
onError?: (
error: TError,
variables: TVariables,
context: TContext | undefined
) => Promise<void> | void
) => Promise<unknown> | void
onSettled?: (
data: TData | undefined,
error: TError | null,
variables: TVariables,
context: TContext | undefined
) => Promise<void> | void
) => Promise<unknown> | void
retry?: RetryValue<TError>
retryDelay?: RetryDelayValue<TError>
useErrorBoundary?: boolean
Expand Down