katanakit-js / InfiniteQueryObserver
Class: InfiniteQueryObserver<TQueryFnData, TError, TData, TQueryKey, TPageParam>
Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:24
An InfiniteQueryObserver extends QueryObserver to observe and switch between infinite queries. It augments the base QueryObserverResult with infinite-query-specific fields and methods, such as hasNextPage and fetchNextPage, and is the primitive that framework adapters (e.g. useInfiniteQuery) build their hooks on top of.
Example
const observer = new InfiniteQueryObserver(queryClient, {
queryKey: ['projects'],
queryFn: ({ pageParam }) => fetchProjects(pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.nextCursor,
})
const unsubscribe = observer.subscribe((result) => console.log(result))Extends
QueryObserver<TQueryFnData,TError,TData,InfiniteData<TQueryFnData,TPageParam>,TQueryKey>
Type Parameters
| Type Parameter | Default type |
|---|---|
TQueryFnData | unknown |
TError | DefaultError |
TData | InfiniteData<TQueryFnData> |
TQueryKey extends QueryKey | QueryKey |
TPageParam | unknown |
Constructors
Constructor
new InfiniteQueryObserver<TQueryFnData, TError, TData, TQueryKey, TPageParam>(client, options): InfiniteQueryObserver<TQueryFnData, TError, TData, TQueryKey, TPageParam>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:28
Parameters
| Parameter | Type |
|---|---|
client | QueryClient |
options | InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> |
Returns
InfiniteQueryObserver<TQueryFnData, TError, TData, TQueryKey, TPageParam>
Overrides
Properties
| Property | Modifier | Type | Description | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|---|
fetch | protected | ReplaceReturnType<(fetchOptions) => Promise<QueryObserverResult<TData, TError>>, Promise<InfiniteQueryObserverResult<TData, TError>>> | - | QueryObserver.fetch | - | node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:27 |
getCurrentResult | public | ReplaceReturnType<() => QueryObserverResult<TData, TError>, InfiniteQueryObserverResult<TData, TError>> | Returns the most recently computed QueryObserverResult for the observed query. This is a point-in-time read; to be notified of updates as they happen, subscribe to the observer instead (its inherited subscribe method). Example const result = observer.getCurrentResult() console.log(result.status, result.data) | QueryObserver.getCurrentResult | - | node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:26 |
listeners | protected | Set<QueryObserverListener<TData, TError>> | - | - | QueryObserver.listeners | node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:8 |
options | public | QueryObserverOptions<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey> | - | - | QueryObserver.options | node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:30 |
subscribe | public | (listener) => () => void | 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(). Example const unsubscribe = subscribable.subscribe(() => { // react to the update }) unsubscribe() | QueryObserver.subscribe | - | node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:25 |
Methods
bindMethods()
protected bindMethods(): void;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:29
Returns
void
Overrides
createResult()
protected createResult(query, options): InfiniteQueryObserverResult<TData, TError>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:82
Parameters
| Parameter | Type |
|---|---|
query | Query<TQueryFnData, TError, InfiniteData<TQueryFnData, TPageParam>, TQueryKey> |
options | InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> |
Returns
InfiniteQueryObserverResult<TData, TError>
Overrides
destroy()
destroy(): void;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:52
Stops observing the current query: clears all listeners, cancels the stale and refetch-interval timers, and removes this observer from the query it was observing.
Returns
void
Inherited from
fetchNextPage()
fetchNextPage(options?): Promise<InfiniteQueryObserverResult<TData, TError>>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:62
Fetches the next page of the infinite query and returns a promise that resolves with the resulting InfiniteQueryObserverResult. The page param used for the fetch is determined by getNextPageParam, which receives the current pages/page params and whose result also determines hasNextPage.
Parameters
| Parameter | Type |
|---|---|
options? | FetchNextPageOptions |
Returns
Promise<InfiniteQueryObserverResult<TData, TError>>
Example
const { hasNextPage } = observer.getCurrentResult()
if (hasNextPage) {
await observer.fetchNextPage()
}See
InfiniteQueryObserver#fetchPreviousPage
fetchOptimistic()
fetchOptimistic(options): Promise<QueryObserverResult<TData, TError>>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:133
Fetches a query defined by the given options without affecting this observer's own tracked query or result, and returns a promise that resolves with the QueryObserverResult for that fetch. This is useful for prefetching data that another observer (e.g. a query about to be navigated to) will need, ahead of time.
Parameters
| Parameter | Type |
|---|---|
options | QueryObserverOptions<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey> |
Returns
Promise<QueryObserverResult<TData, TError>>
Example
const result = await observer.fetchOptimistic({
queryKey: ['posts', 2],
queryFn: () => fetchPost(2),
})
console.log(result.data)Inherited from
fetchPreviousPage()
fetchPreviousPage(options?): Promise<InfiniteQueryObserverResult<TData, TError>>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:81
Fetches the previous page of the infinite query and returns a promise that resolves with the resulting InfiniteQueryObserverResult. The page param used for the fetch is determined by getPreviousPageParam, which receives the current pages/page params and whose result also determines hasPreviousPage.
Parameters
| Parameter | Type |
|---|---|
options? | FetchPreviousPageOptions |
Returns
Promise<InfiniteQueryObserverResult<TData, TError>>
Example
const { hasPreviousPage } = observer.getCurrentResult()
if (hasPreviousPage) {
await observer.fetchPreviousPage()
}See
InfiniteQueryObserver#fetchNextPage
getCurrentQuery()
getCurrentQuery(): Query<TQueryFnData, TError, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:105
Returns the Query instance this observer is currently observing.
Returns
Query<TQueryFnData, TError, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>
Inherited from
getOptimisticResult()
getOptimisticResult(options): InfiniteQueryObserverResult<TData, TError>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:43
The infinite-query counterpart of QueryObserver#getOptimisticResult, marking the options as an infinite query before delegating to it. Called by framework adapters (e.g. useInfiniteQuery) ahead of subscribing, to compute the current InfiniteQueryObserverResult synchronously.
Parameters
| Parameter | Type |
|---|---|
options | DefaultedInfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> |
Returns
InfiniteQueryObserverResult<TData, TError>
Overrides
QueryObserver.getOptimisticResult
hasListeners()
hasListeners(): boolean;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:28
Returns true while at least one listener is registered, false once they have all unsubscribed.
Returns
boolean
Inherited from
onSubscribe()
protected onSubscribe(): void;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:33
Returns
void
Inherited from
onUnsubscribe()
protected onUnsubscribe(): void;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:34
Returns
void
Inherited from
refetch()
refetch(__namedParameters?): Promise<QueryObserverResult<TData, TError>>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:116
Refetches the observed query and returns a promise that resolves with the resulting QueryObserverResult.
Parameters
| Parameter | Type |
|---|---|
__namedParameters? | RefetchOptions |
Returns
Promise<QueryObserverResult<TData, TError>>
Example
const result = await observer.refetch({ cancelRefetch: false })
console.log(result.data)Inherited from
setOptions()
setOptions(options): void;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.d.ts:36
Updates the observer's options. Behaves the same as QueryObserver.setOptions, additionally marking the options as belonging to an infinite query before delegating to the base implementation.
Parameters
| Parameter | Type |
|---|---|
options | InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> |
Returns
void
Overrides
shouldFetchOnReconnect()
shouldFetchOnReconnect(): boolean;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:40
Returns whether the observed query is currently stale and configured (via the refetchOnReconnect option) to refetch when the network reconnects.
Returns
boolean
Inherited from
QueryObserver.shouldFetchOnReconnect
shouldFetchOnWindowFocus()
shouldFetchOnWindowFocus(): boolean;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:46
Returns whether the observed query is currently stale and configured (via the refetchOnWindowFocus option) to refetch when the window regains focus.
Returns
boolean
Inherited from
QueryObserver.shouldFetchOnWindowFocus
trackProp()
trackProp(key): void;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:101
Records that the given QueryObserverResult property was read, so a subsequent update only notifies this observer if a tracked property actually changed. Normally called indirectly via QueryObserver#trackResult's proxy; exposed directly for adapters that track property access themselves (e.g. through their own reactivity system) instead of via the proxy.
Parameters
| Parameter | Type |
|---|---|
key | | "data" | "error" | "status" | "isPending" | "isRefetching" | "refetch" | "isPaused" | "isError" | "isLoading" | "isLoadingError" | "isRefetchError" | "isSuccess" | "isPlaceholderData" | "dataUpdatedAt" | "errorUpdatedAt" | "failureCount" | "failureReason" | "errorUpdateCount" | "isFetched" | "isFetchedAfterMount" | "isFetching" | "isInitialLoading" | "isStale" | "isEnabled" | "fetchStatus" |
Returns
void
Inherited from
trackResult()
trackResult(result, onPropTracked?): QueryObserverResult<TData, TError>;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:94
Wraps a QueryObserverResult in a Proxy that records which properties are read, via QueryObserver#trackProp (and an optional onPropTracked callback). Used by framework adapters when notifyOnChangeProps is not set, to implement its default "only re-render on properties you actually read" behavior.
Parameters
| Parameter | Type |
|---|---|
result | QueryObserverResult<TData, TError> |
onPropTracked? | (key) => void |
Returns
QueryObserverResult<TData, TError>
Inherited from
updateResult()
updateResult(): void;Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/hydration-B9t5w6NC.d.ts:141
Recomputes and stores the current result from the current query/options, notifying listeners if it changed. Framework adapters call this right after subscribing to make sure no query update was missed in the gap between creating the observer and subscribing to it.
Returns
void