Advanced topic
Plumbing most apps never touch: the events a cache subscription receives, the actions that change a query's or mutation's state, the fetch-behaviour hooks behind infinite queries, and the fully resolved Defaulted* options.
Classes
-
DefaultedMutationOptions<
TData, TVariables, TOnMutateResult> Advanced -
Mutation options with every default resolved. Only
QueryClientproduces one, andfinalkeeps it that way; read it fromMutation.optionsorMutationObserver.optionsto see what a mutation actually runs with. -
DefaultedQueryObserverOptions<
TQueryData, TData> Advanced -
QueryObserverOptionsBase with every default resolved:
DefaultedQueryOptions plus the observer-only options, what a
QueryObserveractually runs on. -
DefaultedQueryOptions<
TQueryData> Advanced - QueryOptions with every default resolved: what a Query actually runs on, read back as Query.options.
-
FetchBehavior<
TQueryData> Advanced - Rewrites how a fetch runs.
-
FetchContext<
TQueryData> Advanced - The mutable description of one fetch, handed to a FetchBehavior, which may replace fetchFn to change what the fetch does.
- FetchMore Advanced
-
Which end of an infinite query a fetch is extending. Travels in
FetchOptions.meta, and so ends up inQueryState.fetchMeta. - FetchOptions Advanced
- Overrides for one call of Query.fetch, leaving the query's options untouched.
- MutationAction Advanced
- A state transition. Sealed, so the reducer is exhaustive.
- MutationAdded Advanced
-
A mutation was created and appended to the cache, which happens the moment
mutateis called (or a restored mutation is built into the cache). TanStack Query calls this theaddedevent. - MutationCacheEvent Advanced
-
Something happened to a mutation in the cache. The mutation-side twin of
QueryCacheEvent, delivered toMutationCache.subscribelisteners. - MutationContinueAction Advanced
-
A paused run resumed — or a restored one was re-run.
isPausedbecomes false. - MutationErrorAction Advanced
-
The run failed for good and every error callback has run. Status becomes
error, the data is cleared, and the failure count is bumped one last time. - MutationFailedAction Advanced
-
One attempt failed and will be retried. Records the count and the reason;
status stays
pending. - MutationObserverAdded Advanced
-
An observer subscribed to the mutation, which also cancels its pending
collection. TanStack Query calls this the
observerAddedevent. - MutationObserverOptionsUpdated Advanced
-
An observer's options were replaced while it stayed attached to the same
mutation — a rebuild that changed a callback or
retry, say. TanStack Query calls this theobserverOptionsUpdatedevent. - MutationObserverRef Advanced
- What a Mutation needs from an observer.
- MutationObserverRemoved Advanced
-
An observer unsubscribed from the mutation; when it was the last one, the
collection timer has been armed by the time this fires. TanStack Query
calls this the
observerRemovedevent. - MutationPauseAction Advanced
-
The retryer suspended the run: offline, backgrounded, or blocked by its
scope.
isPausedbecomes true. - MutationPendingAction Advanced
-
A run started. Replaces the whole state: status
pending, the run's variables, a freshsubmittedAt, and isPaused when the run cannot start yet. Dispatched a second time onceonMutatehas run, when it produced a result or the run's pause changed meanwhile. - MutationRemoved Advanced
-
A mutation left the cache: garbage-collected after its last observer
left, or removed through MutationCache.remove or MutationCache.clear.
TanStack Query calls this the
removedevent. - MutationSuccessAction Advanced
-
The mutation function resolved and every success callback has run.
Status becomes
successand the error and failure count are cleared. - MutationUpdated Advanced
-
A mutation's state changed. Emitted for every dispatched MutationAction
— pending, success, error, pause, continue and the rest. TanStack Query
calls this the
updatedevent. - QueryAction Advanced
-
One change to a query's state — what a
QueryUpdatedcache event says happened. - QueryAdded Advanced
-
A query was created and put into the cache, by QueryCache.build or
QueryCache.add — the first time anything used its key. TanStack Query
calls this event
added. - QueryCacheEvent Advanced
-
Something happened to a query in the cache: what
QueryCache.subscribedelivers to its listeners. - QueryContinueAction Advanced
-
A paused fetch resumed;
fetchStatusis fetching again. TanStack Query calls this actioncontinue. - QueryErrorAction Advanced
-
A fetch failed for good: retries exhausted, or cancelled with neither
silentnorrevert— a reverting cancel restores the earlier state through QuerySetStateAction instead. Movesstatusto error, ends the fetch and flags existing data as invalidated. TanStack Query calls this actionerror. - QueryFailedAction Advanced
-
One attempt failed and will be retried. Records the count and the reason
without touching
statusor the data. TanStack Query calls this actionfailed. - QueryFetchAction Advanced
-
A fetch started. Resets the failure count, records meta, and moves
fetchStatusto fetching — or paused, when the network mode forbids starting. TanStack Query calls this actionfetch. - QueryInvalidateAction Advanced
-
The query was marked stale by
QueryClient.invalidateQueries. OnlyisInvalidatedchanges; whether a refetch follows is the caller's decision. TanStack Query calls this actioninvalidate. - QueryObserverAdded Advanced
-
An observer subscribed to the query. Emitted the moment the observer
attaches, which is also what cancels the query's pending garbage
collection. TanStack Query calls this event
observerAdded. - QueryObserverOptionsUpdated Advanced
-
An observer's options were replaced — a rebuild that changed
staleTime,enabledor a callback, say. Emitted for every change of options, a key change included: moving an observer to a different key emits QueryObserverRemoved on the old query and QueryObserverAdded on the new one, and then this event on the new query. TanStack Query calls this eventobserverOptionsUpdatedand orders it the same way. - QueryObserverRef Advanced
- What a Query needs from an observer, without knowing what an observer is.
- QueryObserverRemoved Advanced
-
An observer unsubscribed from the query. Emitted after the observer has
been detached — and, when it was the last one, after the fetch in flight
has been told to stop retrying and the garbage-collection timer has been
started. TanStack Query calls this event
observerRemoved. - QueryObserverResultsUpdated Advanced
-
An observer of the query delivered a new result to its listeners. Emitted
once per delivery, after the listeners have run, so a devtools panel can
mirror what the UI just saw. TanStack Query calls this event
observerResultsUpdated. - QueryPauseAction Advanced
-
The fetch was suspended: the device is offline, or a retry is waiting
for the app to return to the foreground.
fetchStatusbecomes paused. TanStack Query calls this actionpause. - QueryRemoved Advanced
-
A query left the cache: it was garbage-collected after its
gcTimewithout observers, or removed throughQueryClient.removeQueries, QueryCache.remove or QueryCache.clear. TanStack Query calls this eventremoved. -
QuerySetStateAction<
TQueryData> Advanced -
The whole state was replaced through Query.setState — a reset, a
revert after cancellation, or a persistence layer restoring. TanStack
Query calls this action
setState. -
QuerySuccessAction<
TQueryData> Advanced -
Data arrived: from a fetch, or from a manual write through
QueryClient.setQueryData. BumpsdataUpdateCount, clears the error and the invalidation, and — unless manual — ends the fetch. TanStack Query calls this actionsuccess. - QueryUpdated Advanced
-
A query's state changed. Emitted for every QueryAction — fetch,
success, error, invalidate, pause, and the rest — so this is the event a
devtools panel or a persister keys its work off. TanStack Query calls
this event
updated.