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

CreateMutationOptions.md

57 lines3.7 KB

1---
2id: CreateMutationOptions
3title: CreateMutationOptions
4---
5​
6Defined in: [packages/angular-query/src/types.ts:295](https://github.com/TanStack/query/blob/main/packages/angular-query/src/types.ts#L295)
7​
8The options accepted by `injectMutation`. Same as [MutationObserverOptions](MutationObserverOptions.md) from
9`@tanstack/query-core`, minus the internal `_defaulted` flag.
10​
11## Extends
12​
13- [`OmitKeyof`](../type-aliases/OmitKeyof.md)\<[`MutationObserverOptions`](MutationObserverOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>, `"_defaulted"` \| `"throwOnError"`\>
14​
15## Type Parameters
16​
17### TData
18​
19`TData` = `unknown`
20​
21The type your mutation function resolves to.
22​
23### TError
24​
25`TError` = [`DefaultError`](../type-aliases/DefaultError.md)
26​
27The type of errors your mutation function may throw.
28​
29### TVariables
30​
31`TVariables` = `void`
32​
33The type of the variable passed to `mutate`/`mutateAsync`.
34​
35### TOnMutateResult
36​
37`TOnMutateResult` = `unknown`
38​
39The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
40their `onMutateResult` parameter β€” useful for optimistic-update rollback data.
41​
42## Properties
43​
44| Property | Type | Description |
45| ------ | ------ | ------ |
46| <a id="gctime"></a> `gcTime?` | `number` | The time in milliseconds that an unused/inactive mutation remains in memory before it is garbage collected. Defaults to `5 * 60 * 1000` (5 minutes), or `Infinity` during SSR. |
47| <a id="meta"></a> `meta?` | `Record`\<`string`, `unknown`\> | - |
48| <a id="mutationfn"></a> `mutationFn?` | [`MutationFunction`](../type-aliases/MutationFunction.md)\<`TData`, `TVariables`\> | - |
49| <a id="mutationkey"></a> `mutationKey?` | readonly `unknown`[] | - |
50| <a id="networkmode"></a> `networkMode?` | [`NetworkMode`](../type-aliases/NetworkMode.md) | Controls whether a mutation is allowed to run based on the current network connectivity. Defaults to `'online'`. **See** [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information. |
51| <a id="onerror"></a> `onError?` | (`error`: `TError`, `variables`: `TVariables`, `onMutateResult`: `TOnMutateResult` \| `undefined`, `context`: [`MutationFunctionContext`](../type-aliases/MutationFunctionContext.md)) => `unknown` | - |
52| <a id="onmutate"></a> `onMutate?` | (`variables`: `TVariables`, `context`: [`MutationFunctionContext`](../type-aliases/MutationFunctionContext.md)) => `TOnMutateResult` \| `Promise`\<`TOnMutateResult`\> | - |
53| <a id="onsettled"></a> `onSettled?` | (`data`: `TData` \| `undefined`, `error`: `TError` \| `null`, `variables`: `TVariables`, `onMutateResult`: `TOnMutateResult` \| `undefined`, `context`: [`MutationFunctionContext`](../type-aliases/MutationFunctionContext.md)) => `unknown` | - |
54| <a id="onsuccess"></a> `onSuccess?` | (`data`: `TData`, `variables`: `TVariables`, `onMutateResult`: `TOnMutateResult`, `context`: [`MutationFunctionContext`](../type-aliases/MutationFunctionContext.md)) => `unknown` | - |
55| <a id="retry"></a> `retry?` | `RetryValue`\<`TError`\> | If `false`, failed mutations will not retry by default. If `true`, failed mutations will retry infinitely. If set to an integer number, e.g. 3, failed mutations will retry until the failed mutation count meets that number. If set to a function `(failureCount, error) => boolean` failed mutations will retry until the function returns false. Defaults to `0`. |
56| <a id="retrydelay"></a> `retryDelay?` | `RetryDelayValue`\<`TError`\> | This function receives a `retryAttempt` integer and the actual Error and returns the delay to apply before the next attempt in milliseconds. Defaults to a function that applies exponential backoff, capped at 30 seconds. |
57| <a id="scope"></a> `scope?` | [`MutationScope`](../type-aliases/MutationScope.md) | - |