- 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
QueriesObserver
Defined in: packages/query-core/src/queriesObserver.ts:64
A QueriesObserver watches an array of queries at once, exposing them as a single array of QueryObserverResults (or, when a combine option is given, as a combined value derived from that array). It manages one internal QueryObserver per query, and is the primitive that framework adapters (e.g. useQueries) build their hooks on top of.
Example#
const observer = new QueriesObserver(queryClient, [
{ queryKey: ['post', 1], queryFn: fetchPost },
{ queryKey: ['post', 2], queryFn: fetchPost },
])
const unsubscribe = observer.subscribe((result) => {
console.log(result)
})Extends#
- Subscribable<QueriesObserverListener>
Type Parameters#
TCombinedResult#
TCombinedResult = QueryObserverResult[]
Constructors#
Constructor#
new QueriesObserver<TCombinedResult = QueryObserverResult[]>(
client: QueryClient,
queries: QueryObserverOptions<any, any, any, any, any, never>[],
options?: QueriesObserverOptions<TCombinedResult>
): QueriesObserver<TCombinedResult>;Defined in: packages/query-core/src/queriesObserver.ts:78
Parameters#
client#
queries#
QueryObserverOptions<any, any, any, any, any, never>[]
options?#
QueriesObserverOptions<TCombinedResult>
Returns#
QueriesObserver<TCombinedResult>
Overrides#
Subscribable<QueriesObserverListener>.constructorMethods#
destroy()#
destroy(): void;Defined in: packages/query-core/src/queriesObserver.ts:114
Stops observing all queries: clears all listeners and destroys every underlying QueryObserver this observer manages.
Returns#
void
getCurrentResult()#
getCurrentResult(): QueryObserverResult[];Defined in: packages/query-core/src/queriesObserver.ts:219
Returns the most recently computed array of QueryObserverResults, one per observed query, in the same order as the queries passed to the constructor or setQueries.
Returns#
The current results.
Example#
const results = observer.getCurrentResult()
const data = results.map((result) => result.data)getObservers()#
getObservers(): QueryObserver<unknown, Error, unknown, unknown, readonly unknown[]>[];Defined in: packages/query-core/src/queriesObserver.ts:238
Returns the underlying QueryObserver instances this observer manages, in the same order as the queries passed to the constructor or setQueries.
Returns#
QueryObserver<unknown, Error, unknown, unknown, readonly unknown[]>[]
The managed query observers.
getOptimisticResult()#
getOptimisticResult(queries: QueryObserverOptions<unknown, Error, unknown, unknown, readonly unknown[], never>[], combine: CombineFn<TCombinedResult> | undefined): [rawResult: QueryObserverResult[], combineResult: (r?: QueryObserverResult[]) => TCombinedResult, trackResult: () => QueryObserverResult[]];Defined in: packages/query-core/src/queriesObserver.ts:253
The QueriesObserver counterpart of QueryObserver#getOptimisticResult — computes the result for the given (already-defaulted) queries right now, synchronously. Called by framework adapters (e.g. useQueries) ahead of subscribing, returning a tuple of the raw per-query results, a function to compute the combined result from them, and a function to wrap the results for property-access tracking.
Parameters#
queries#
QueryObserverOptions<unknown, Error, unknown, unknown, readonly unknown[], never>[]
The defaulted options of the queries to compute the result for.
combine#
CombineFn<TCombinedResult> | undefined
The combine function used by the returned combineResult, if any.
Returns#
[rawResult: QueryObserverResult[], combineResult: (r?: QueryObserverResult[]) => TCombinedResult, trackResult: () => QueryObserverResult[]]
A tuple of the per-query results, a function that computes the combined result, and a function that returns the results wrapped for property-access tracking.
getQueries()#
getQueries(): Query<unknown, Error, unknown, readonly unknown[]>[];Defined in: packages/query-core/src/queriesObserver.ts:228
Returns the underlying Query instances currently being observed, in the same order as the queries passed to the constructor or setQueries.
Returns#
Query<unknown, Error, unknown, readonly unknown[]>[]
The observed queries.
hasListeners()#
hasListeners(): boolean;Defined in: packages/query-core/src/subscribable.ts:43
Returns true while at least one listener is registered, false once they have all unsubscribed.
Returns#
boolean
true if at least one listener is registered.
Inherited from#
Subscribable.hasListenerssetQueries()#
setQueries(queries: QueryObserverOptions<unknown, Error, unknown, unknown, readonly unknown[], never>[], options?: QueriesObserverOptions<TCombinedResult>): void;Defined in: packages/query-core/src/queriesObserver.ts:136
Replaces the set of queries being observed. Existing QueryObservers are reused for queries that match an already-observed query hash; observers for queries that are no longer present are destroyed, and new observers are created and subscribed to for newly added queries.
Parameters#
queries#
QueryObserverOptions<unknown, Error, unknown, unknown, readonly unknown[], never>[]
The options of the queries to observe.
options?#
QueriesObserverOptions<TCombinedResult>
Replaces the observer's options, e.g. its combine function.
Returns#
void
Example#
observer.setQueries([
{ queryKey: ['post', 1], queryFn: fetchPost },
{ queryKey: ['post', 3], queryFn: fetchPost },
])subscribe()#
subscribe(listener: QueriesObserverListener): () => void;Defined in: packages/query-core/src/subscribable.ts:28
Registers a listener to be called on every update this object notifies about. Returns a function that removes the listener again — call it to stop listening. The base class never drops a listener on its own, though some subclasses clear all of theirs in destroy().
Parameters#
listener#
QueriesObserverListener
Called on each update, with whatever the subclass passes to its subscribers.
Returns#
A function that removes the listener.
() => void
Example#
const unsubscribe = subscribable.subscribe(() => {
// react to the update
})
unsubscribe()Inherited from#
Subscribable.subscribe