Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

MutationObserverBaseResult.md

60 lines4.8 KB

1---
2id: MutationObserverBaseResult
3title: MutationObserverBaseResult
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8Defined in: [packages/query-core/src/types.ts:2086](https://github.com/TanStack/query/blob/main/packages/query-core/src/types.ts#L2086)
9​
10The properties shared by every state of a mutation result, like `data`, `error`, `variables`,
11`status`, the `is*` flags, `mutate`, and `reset`.
12​
13## Extends
14​
15- [`MutationState`](MutationState.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
16​
17## Extended by
18​
19- [`MutationObserverIdleResult`](MutationObserverIdleResult.md)
20- [`MutationObserverLoadingResult`](MutationObserverLoadingResult.md)
21- [`MutationObserverErrorResult`](MutationObserverErrorResult.md)
22- [`MutationObserverSuccessResult`](MutationObserverSuccessResult.md)
23​
24## Type Parameters
25​
26### TData
27​
28`TData` = `unknown`
29​
30### TError
31​
32`TError` = [`DefaultError`](../type-aliases/DefaultError.md)
33​
34### TVariables
35​
36`TVariables` = `void`
37​
38### TOnMutateResult
39​
40`TOnMutateResult` = `unknown`
41​
42## Properties
43​
44| Property | Type | Description | Overrides |
45| ------ | ------ | ------ | ------ |
46| <a id="property-context"></a> `context` | `TOnMutateResult` \| `undefined` | The value returned by `onMutate`, if defined. Passed to `onSuccess`, `onError` and `onSettled` as the mutation's context. | - |
47| <a id="property-data"></a> `data` | `TData` \| `undefined` | The last successfully resolved data for the mutation. | [`MutationState`](MutationState.md).[`data`](MutationState.md#property-data) |
48| <a id="property-error"></a> `error` | `TError` \| `null` | The error object for the mutation, if an error was encountered. - Defaults to `null`. | [`MutationState`](MutationState.md).[`error`](MutationState.md#property-error) |
49| <a id="property-failurecount"></a> `failureCount` | `number` | The number of times the mutation function has failed for the current attempt. | - |
50| <a id="property-failurereason"></a> `failureReason` | `TError` \| `null` | The reason the current attempt failed, as reported by the retryer. | - |
51| <a id="property-iserror"></a> `isError` | `boolean` | A boolean variable derived from `status`. - `true` if the last mutation attempt resulted in an error. | - |
52| <a id="property-isidle"></a> `isIdle` | `boolean` | A boolean variable derived from `status`. - `true` if the mutation is in its initial state prior to executing. | - |
53| <a id="property-ispaused"></a> `isPaused` | `boolean` | Whether the mutation is currently paused (see network mode), or is waiting for another mutation with the same `scope` to finish. | - |
54| <a id="property-ispending"></a> `isPending` | `boolean` | A boolean variable derived from `status`. - `true` if the mutation is currently executing. | - |
55| <a id="property-issuccess"></a> `isSuccess` | `boolean` | A boolean variable derived from `status`. - `true` if the last mutation attempt was successful. | - |
56| <a id="property-mutate"></a> `mutate` | [`MutateFunction`](../type-aliases/MutateFunction.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\> | The mutation function you can call with variables to trigger the mutation and optionally hooks on additional callback options. **Param** **variables** The variables object to pass to the `mutationFn`. **Param** **options.onSuccess** This function will fire when the mutation is successful and will be passed the mutation's result. **Param** **options.onError** This function will fire if the mutation encounters an error and will be passed the error. **Param** **options.onSettled** This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error. **Remarks** - If you make multiple requests, `onSuccess` will fire only after the latest call you've made. - All the callback functions (`onSuccess`, `onError`, `onSettled`) are void functions, and the returned value will be ignored. | - |
57| <a id="property-reset"></a> `reset` | () => `void` | A function to clean the mutation internal state (i.e., it resets the mutation to its initial state). | - |
58| <a id="property-status"></a> `status` | `"error"` \| `"idle"` \| `"pending"` \| `"success"` | The status of the mutation. - Will be: - `idle` initial status prior to the mutation function executing. - `pending` if the mutation is currently executing. - `error` if the last mutation attempt resulted in an error. - `success` if the last mutation attempt was successful. | [`MutationState`](MutationState.md).[`status`](MutationState.md#property-status) |
59| <a id="property-submittedat"></a> `submittedAt` | `number` | The timestamp for when the mutation was submitted. | - |
60| <a id="property-variables"></a> `variables` | `TVariables` \| `undefined` | The variables object passed to the `mutationFn`. | [`MutationState`](MutationState.md).[`variables`](MutationState.md#property-variables) |