Skip to content

Docs: update mutate options description #4133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 11, 2022
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
13 changes: 12 additions & 1 deletion docs/reference/useMutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,18 @@ mutate(variables, {
- `variables: TVariables`
- Optional
- The variables object to pass to the `mutationFn`.
- Remaining options extend the same options described above in the `useMutation` hook.
- `onSuccess: (data: TData, variables: TVariables, context: TContext) => void`
- Optional
- This function will fire when the mutation is successful and will be passed the mutation's result.
- Void function, the returned value will be ignored
- `onError: (err: TError, variables: TVariables, context: TContext | undefined) => void`
- Optional
- This function will fire if the mutation encounters an error and will be passed the error.
- Void function, the returned value will be ignored
- `onSettled: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => 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
- Void function, the returned value will be ignored
- If you make multiple requests, `onSuccess` will fire only after the latest call you've made.
- `mutateAsync: (variables: TVariables, { onSuccess, onSettled, onError }) => Promise<TData>`
- Similar to `mutate` but returns a promise which can be awaited.
Expand Down
10 changes: 3 additions & 7 deletions packages/query-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,22 +576,18 @@ export interface MutateOptions<
TVariables = void,
TContext = unknown,
> {
onSuccess?: (
data: TData,
variables: TVariables,
context: TContext,
) => Promise<unknown> | unknown
onSuccess?: (data: TData, variables: TVariables, context: TContext) => void
onError?: (
error: TError,
variables: TVariables,
context: TContext | undefined,
) => Promise<unknown> | unknown
) => void
onSettled?: (
data: TData | undefined,
error: TError | null,
variables: TVariables,
context: TContext | undefined,
) => Promise<unknown> | unknown
) => void
}

export type MutateFunction<
Expand Down