Defined in: packages/query-core/src/mutationCache.ts:26
Global callbacks that fire for every mutation handled by a MutationCache, regardless of which component or observer triggered it. They differ from the defaultOptions provided to a QueryClient in two ways: defaultOptions can be overridden by each mutation, while these callbacks are always called, and onMutate here does not allow returning a result.
If a callback returns a promise, it will be awaited before the mutation continues.
| Property | Type | Description |
|---|---|---|
| onError? | (error: Error, variables: unknown, onMutateResult: unknown, mutation: Mutation<unknown, unknown, unknown>, context: MutationFunctionContext) => unknown | Called when any mutation in the cache encounters an error. |
| onMutate? | (variables: unknown, mutation: Mutation<unknown, unknown, unknown>, context: MutationFunctionContext) => unknown | Called before any mutation in the cache executes. |
| onSettled? | (data: unknown, error: Error | null, variables: unknown, onMutateResult: unknown, mutation: Mutation<unknown, unknown, unknown>, context: MutationFunctionContext) => unknown | Called when any mutation in the cache is settled, either successfully or with an error. |
| onSuccess? | (data: unknown, variables: unknown, onMutateResult: unknown, mutation: Mutation<unknown, unknown, unknown>, context: MutationFunctionContext) => unknown | Called when any mutation in the cache is successful. |