- Lit Reference
- Classes / CancelledError
- Classes / InfiniteQueryObserver
- Classes / Mutation
- Classes / MutationCache
- Classes / MutationObserver
- Classes / QueriesObserver
- Classes / Query
- Classes / QueryCache
- Classes / QueryClient
- Classes / QueryClientProvider
- Classes / QueryObserver
- Functions / createInfiniteQueryController
- Functions / createMutationController
- Functions / createQueriesController
- Functions / createQueryController
- Functions / defaultShouldDehydrateMutation
- Functions / defaultShouldDehydrateQuery
- Functions / dehydrate
- Functions / dehydrateQuery
- Functions / experimental_streamedQuery
- Functions / hashKey
- Functions / hydrate
- Functions / infiniteQueryOptions
- Functions / isCancelledError
- Functions / keepPreviousData
- Functions / matchMutation
- Functions / matchQuery
- Functions / mutationOptions
- Functions / noop
- Functions / partialMatchKey
- Functions / queryOptions
- Functions / replaceEqualDeep
- Functions / shouldThrowError
- Functions / useIsFetching
- Functions / useIsMutating
- Functions / useMutationState
- Functions / useQueryClient
- Context / queryClientContext
- Context / getDefaultQueryClient
- Context / registerDefaultQueryClient
- Context / unregisterDefaultQueryClient
- Context / resolveQueryClient
- Interfaces / CancelOptions
- 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 / 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 / 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 / Accessor
- Types / AnyDataTag
- Types / CreateInfiniteQueryOptions
- Types / CreateMutationOptions
- Types / CreateQueriesControllerOptions
- Types / CreateQueriesInput
- Types / CreateQueryOptions
- Types / DataTag
- Types / DefaultError
- Types / DefaultedInfiniteQueryObserverOptions
- Types / DefaultedQueryObserverOptions
- Types / DefinedInfiniteQueryObserverResult
- Types / DefinedInitialDataOptions
- Types / DefinedQueryObserverResult
- Types / DistributiveOmit
- Types / EnsureInfiniteQueryDataOptions
- Types / FetchInfiniteQueryOptions
- Types / FetchStatus
- Types / GetNextPageParamFunction
- Types / GetPreviousPageParamFunction
- Types / InferDataFromTag
- Types / InferErrorFromTag
- Types / InfiniteQueryControllerOptions
- Types / InfiniteQueryExecuteOptions
- Types / InfiniteQueryObserverResult
- Types / InfiniteQueryResultAccessor
- Types / InitialDataFunction
- Types / IsFetchingAccessor
- Types / IsMutatingAccessor
- Types / ManagedTimerId
- Types / MutateFunction
- Types / MutateFunctionRest
- Types / MutationCacheNotifyEvent
- Types / MutationControllerOptions
- Types / MutationControllerResult
- Types / MutationFunction
- Types / MutationFunctionContext
- Types / MutationKey
- Types / MutationMeta
- Types / MutationObserverResult
- Types / MutationResultAccessor
- Types / MutationScope
- Types / MutationStateAccessor
- Types / MutationStateOptions
- Types / MutationStatus
- Types / NetworkMode
- Types / NonUndefinedGuard
- Types / NotifyEventType
- Types / NotifyOnChangeProps
- Types / OmitKeyof
- Types / Override
- Types / PlaceholderDataFunction
- Types / QueriesControllerOptions
- Types / QueriesPlaceholderDataFunction
- Types / QueriesResultAccessor
- Types / QueryBooleanOption
- Types / QueryCacheNotifyEvent
- Types / QueryControllerOptions
- Types / QueryControllerResult
- Types / QueryFunction
- Types / QueryFunctionContext
- Types / QueryKey
- Types / QueryKeyHashFunction
- Types / QueryKeyWithDataTag
- Types / QueryMeta
- Types / QueryObserverResult
- Types / QueryPersister
- Types / QueryResultAccessor
- Types / QueryStatus
- Types / SkipToken
- Types / StaleTime
- Types / StaleTimeFunction
- Types / ThrowOnError
- Types / TimeoutCallback
- Types / TimeoutProvider
- Types / UndefinedInitialDataOptions
- Types / UnsetMarker
- Types / UnusedSkipTokenOptions
- Types / Updater
- Types / ValueAccessor
- 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
useMutationState
function useMutationState<TResult = MutationState<unknown, unknown, unknown, unknown>>(
host: ReactiveControllerHost,
options?: MutationStateOptions<TResult>,
queryClient?: QueryClient
): MutationStateAccessor<TResult>;Defined in: packages/lit-query/src/useMutationState.ts:186
Creates a Lit reactive controller that selects state from matching mutations in the mutation cache.
When options.filters is a function, it is re-read during host updates so the selection can follow reactive host state. If queryClient is omitted, the controller resolves the client from the nearest connected QueryClientProvider.
Type Parameters#
TResult#
TResult = MutationState<unknown, unknown, unknown, unknown>
Parameters#
host#
ReactiveControllerHost
The Lit reactive controller host that owns the mutation cache subscription.
options?#
MutationStateOptions<TResult> = {}
Mutation state filters and optional selector.
options properties#
| Property | Type | Description |
|---|---|---|
| filters? | Accessor<MutationFilters> | Filters used to select mutations from the mutation cache. |
| select? | (mutation: Mutation) => TResult | Maps each matching mutation to the value returned by the accessor. |
queryClient?#
Optional explicit query client. Provide this for controllers that should not resolve a client from Lit context.
Returns#
MutationStateAccessor<TResult>
An accessor for the selected mutation state array.
Example#
import { LitElement, html } from 'lit'
import { useMutationState } from '@tanstack/lit-query'
class PendingUploads extends LitElement {
private readonly uploads = useMutationState(this, {
filters: { mutationKey: ['upload'], status: 'pending' },
select: (mutation) => mutation.state.variables as File,
})
render() {
return html`<span>${this.uploads().length} uploads pending</span>`
}
}