- Angular Reference
- Functions / defaultShouldDehydrateMutation
- Functions / defaultShouldDehydrateQuery
- Functions / dehydrate
- Functions / dehydrateQuery
- Functions / experimental_streamedQuery
- Functions / hashKey
- Functions / hydrate
- Functions / infiniteQueryOptions
- Functions / injectInfiniteQuery
- Functions / injectIsFetching
- Functions / injectIsMutating
- Functions / injectIsRestoring
- Functions / injectMutation
- Functions / injectMutationState
- Functions / injectQuery
- Functions / injectQueryClient
- Functions / isCancelledError
- Functions / keepPreviousData
- Functions / matchMutation
- Functions / matchQuery
- Functions / mutationOptions
- Functions / noop
- Functions / partialMatchKey
- Functions / provideAngularQuery
- Functions / provideIsRestoring
- Functions / provideQueryClient
- Functions / provideTanStackQuery
- Functions / queryFeature
- Functions / queryOptions
- Functions / replaceEqualDeep
- Functions / shouldThrowError
- Classes / CancelledError
- Classes / InfiniteQueryObserver
- Classes / Mutation
- Classes / MutationCache
- Classes / MutationObserver
- Classes / QueriesObserver
- Classes / Query
- Classes / QueryCache
- Classes / QueryClient
- Classes / QueryObserver
- Interfaces / BaseMutationNarrowing
- Interfaces / BaseQueryNarrowing
- Interfaces / CancelOptions
- Interfaces / CreateBaseQueryOptions
- Interfaces / CreateInfiniteQueryOptions
- Interfaces / CreateMutationOptions
- Interfaces / CreateQueryOptions
- Interfaces / DefaultOptions
- Interfaces / DehydrateOptions
- Interfaces / DehydratedState
- Interfaces / EnsureQueryDataOptions
- Interfaces / FetchNextPageOptions
- Interfaces / FetchPreviousPageOptions
- Interfaces / FetchQueryOptions
- Interfaces / FocusManager
- Interfaces / HydrateOptions
- Interfaces / InfiniteData
- Interfaces / InfiniteQueryObserverBaseResult
- Interfaces / InfiniteQueryObserverLoadingErrorResult
- Interfaces / InfiniteQueryObserverLoadingResult
- Interfaces / InfiniteQueryObserverOptions
- Interfaces / InfiniteQueryObserverPendingResult
- Interfaces / InfiniteQueryObserverPlaceholderResult
- Interfaces / InfiniteQueryObserverRefetchErrorResult
- Interfaces / InfiniteQueryObserverSuccessResult
- Interfaces / InfiniteQueryPageParamsOptions
- Interfaces / InitialPageParam
- Interfaces / InjectInfiniteQueryOptions
- Interfaces / InjectIsFetchingOptions
- Interfaces / InjectIsMutatingOptions
- Interfaces / InjectMutationOptions
- Interfaces / InjectMutationStateOptions
- Interfaces / InjectQueryOptions
- Interfaces / InvalidateOptions
- Interfaces / InvalidateQueryFilters
- Interfaces / MutateOptions
- Interfaces / MutationCacheConfig
- Interfaces / MutationFilters
- Interfaces / MutationObserverBaseResult
- Interfaces / MutationObserverErrorResult
- Interfaces / MutationObserverIdleResult
- Interfaces / MutationObserverLoadingResult
- Interfaces / MutationObserverOptions
- Interfaces / MutationObserverSuccessResult
- Interfaces / MutationOptions
- Interfaces / MutationState
- Interfaces / NotifyEvent
- Interfaces / OnlineManager
- Interfaces / QueriesObserverOptions
- Interfaces / QueryCacheConfig
- Interfaces / QueryClientConfig
- Interfaces / QueryExecuteOptions
- Interfaces / QueryFeature
- Interfaces / QueryFilters
- Interfaces / QueryObserverBaseResult
- Interfaces / QueryObserverLoadingErrorResult
- Interfaces / QueryObserverLoadingResult
- Interfaces / QueryObserverOptions
- Interfaces / QueryObserverPendingResult
- Interfaces / QueryObserverPlaceholderResult
- Interfaces / QueryObserverRefetchErrorResult
- Interfaces / QueryObserverSuccessResult
- Interfaces / QueryOptions
- Interfaces / QueryState
- Interfaces / RefetchOptions
- Interfaces / RefetchQueryFilters
- Interfaces / Register
- Interfaces / ResetOptions
- Interfaces / ResultOptions
- Interfaces / SetDataOptions
- Interfaces / TimeoutManager
- Types / AnyDataTag
- Types / CreateBaseMutationResult
- Types / CreateBaseQueryResult
- Types / CreateInfiniteQueryResult
- Types / CreateMutateAsyncFunction
- Types / CreateMutateFunction
- Types / CreateMutationResult
- Types / CreateQueryResult
- Types / DataTag
- Types / DefaultError
- Types / DefaultedInfiniteQueryObserverOptions
- Types / DefaultedQueryObserverOptions
- Types / DefinedCreateInfiniteQueryResult
- Types / DefinedCreateQueryResult
- Types / DefinedInfiniteQueryObserverResult
- Types / DefinedInitialDataInfiniteOptions
- Types / DefinedInitialDataOptions
- Types / DefinedQueryObserverResult
- Types / DevtoolsFeature
- Types / DistributiveOmit
- Types / EnsureInfiniteQueryDataOptions
- Types / FetchInfiniteQueryOptions
- Types / FetchStatus
- Types / GetNextPageParamFunction
- Types / GetPreviousPageParamFunction
- Types / InferDataFromTag
- Types / InferErrorFromTag
- Types / InfiniteQueryExecuteOptions
- Types / InfiniteQueryObserverResult
- Types / InitialDataFunction
- Types / ManagedTimerId
- Types / MutateFunction
- Types / MutateFunctionRest
- Types / MutationCacheNotifyEvent
- Types / MutationFunction
- Types / MutationFunctionContext
- Types / MutationKey
- Types / MutationMeta
- Types / MutationObserverResult
- Types / MutationScope
- Types / MutationStatus
- Types / NetworkMode
- Types / NonUndefinedGuard
- Types / NotifyEventType
- Types / NotifyOnChangeProps
- Types / OmitKeyof
- Types / Override
- Types / PersistQueryClientFeature
- Types / PlaceholderDataFunction
- Types / QueriesOptions
- Types / QueriesPlaceholderDataFunction
- Types / QueriesResults
- Types / QueryBooleanOption
- Types / QueryCacheNotifyEvent
- Types / QueryFeatures
- Types / QueryFunction
- Types / QueryFunctionContext
- Types / QueryKey
- Types / QueryKeyHashFunction
- Types / QueryKeyWithDataTag
- Types / QueryMeta
- Types / QueryObserverResult
- Types / QueryPersister
- Types / QueryStatus
- Types / SkipToken
- Types / StaleTime
- Types / StaleTimeFunction
- Types / ThrowOnError
- Types / TimeoutCallback
- Types / TimeoutProvider
- Types / UndefinedInitialDataInfiniteOptions
- Types / UndefinedInitialDataOptions
- Types / UnsetMarker
- Types / UnusedSkipTokenInfiniteOptions
- Types / UnusedSkipTokenOptions
- Types / Updater
- Types / WithRequired
- Types / dataTagErrorSymbol
- Types / dataTagSymbol
- Variables / dataTagErrorSymbol
- Variables / dataTagSymbol
- Variables / defaultScheduler
- Variables / environmentManager
- Variables / focusManager
- Variables / isServer
- Variables / notifyManager
- Variables / onlineManager
- Variables / skipToken
- Variables / timeoutManager
- Variables / unsetMarker
mutationOptions
Overview#
function mutationOptions<TData = unknown, TError = Error, TVariables = void, TOnMutateResult = unknown>(options: WithRequired<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">): WithRequired<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">;
function mutationOptions<TData = unknown, TError = Error, TVariables = void, TOnMutateResult = unknown>(options: Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">): Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">;- WithRequired<CreateMutationOptions> → WithRequired<CreateMutationOptions>: You can generally pass everything to mutationOptions that you can also pass to injectMutation. A mutationKey is required on this overload so the mutation can be looked up later, e.g. with injectMutationState.
- Omit<CreateMutationOptions> → Omit<CreateMutationOptions>: You can generally pass everything to mutationOptions that you can also pass to injectMutation. No mutationKey is required on this overload — use this when you don't need to target the mutation via a mutationKey filter later (e.g. with injectMutationState); it can still be observed through other filters, such as status.
See also: Parameters · Returns
Call Signature#
function mutationOptions<TData = unknown, TError = Error, TVariables = void, TOnMutateResult = unknown>(options: WithRequired<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">): WithRequired<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">;Defined in: packages/angular-query-experimental/src/mutation-options.ts:38
You can generally pass everything to mutationOptions that you can also pass to injectMutation. A mutationKey is required on this overload so the mutation can be looked up later, e.g. with injectMutationState.
Type Parameters#
TData#
TData = unknown
TError#
TError = Error
TVariables#
TVariables = void
TOnMutateResult#
TOnMutateResult = unknown
Parameters#
options#
WithRequired<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">
The mutation options to use, identical to what you'd pass to injectMutation, with a required mutationKey.
Returns#
WithRequired<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">
The same options object, unchanged.
See#
injectMutation to run the mutation these options describe.
Example#
Looking the mutation up elsewhere via its mutationKey, e.g. for a global "saving…" indicator:
import { mutationOptions, injectMutationState } from '@tanstack/angular-query-experimental'
const createPostOptions = mutationOptions({
mutationKey: ['posts', 'create'],
mutationFn: createPost,
})
@Component({
selector: 'saving-indicator',
template: `
@if (isCreatingPost()) {
<span>Saving…</span>
}
`,
})
export class SavingIndicator {
readonly #pendingCreates = injectMutationState(() => ({
filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },
}))
readonly isCreatingPost = computed(() => this.#pendingCreates().length > 0)
}Call Signature#
function mutationOptions<TData = unknown, TError = Error, TVariables = void, TOnMutateResult = unknown>(options: Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">): Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">;Defined in: packages/angular-query-experimental/src/mutation-options.ts:94
You can generally pass everything to mutationOptions that you can also pass to injectMutation. No mutationKey is required on this overload — use this when you don't need to target the mutation via a mutationKey filter later (e.g. with injectMutationState); it can still be observed through other filters, such as status.
Type Parameters#
TData#
TData = unknown
TError#
TError = Error
TVariables#
TVariables = void
TOnMutateResult#
TOnMutateResult = unknown
Parameters#
options#
Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">
The mutation options to use, identical to what you'd pass to injectMutation, without a mutationKey.
Returns#
Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">
The same options object, unchanged.
Remarks#
See the other overload's example for looking a mutation up via injectMutationState.
See#
injectMutation to run the mutation these options describe.
Example#
Sharing options across services, so QueriesService stays the single place a mutation is defined:
import { mutationOptions, injectMutation } from '@tanstack/angular-query-experimental'
@Injectable({ providedIn: 'root' })
export class QueriesService {
readonly #queryClient = inject(QueryClient)
updatePost(id: number) {
return mutationOptions({
mutationFn: (post: Partial<Post>) => putPost(id, post),
onSuccess: (newPost) => this.#queryClient.setQueryData(['posts', id], newPost),
})
}
}
@Component({
selector: 'post',
template: `<button (click)="save()">Save</button>`,
})
export class Post {
readonly queries = inject(QueriesService)
readonly id = signal(0)
readonly updatePostMutation = injectMutation(() => this.queries.updatePost(this.id()))
save() {
this.updatePostMutation.mutate({ title: 'New Title' })
}
}Parameters#
options#
Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">
The mutation options to use, identical to what you'd pass to injectMutation, without a mutationKey.
options properties#
Built from CreateMutationOptions. See the type above for what it changes.
Returns#
Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, "mutationKey">
The same options object, unchanged.
Result properties#
Built from CreateMutationOptions. See the type above for what it changes.