@tanstack/query-core
Version:
The framework agnostic core that powers TanStack Query
92 lines • 5.71 kB
TypeScript
import { t as Subscribable } from "./subscribable-czlHOxMP.js";
import { $n as Query, A as InfiniteData, C as FetchPreviousPageOptions, Ct as QueryKey, F as InfiniteQueryObserverOptions, S as FetchNextPageOptions, f as DefaultError, m as DefaultedInfiniteQueryObserverOptions, on as QueryClient, rr as QueryObserver, z as InfiniteQueryObserverResult } from "./hydration-Bf0oMcwO.js";
//#region src/infiniteQueryObserver.d.ts
type InfiniteQueryObserverListener<TData, TError> = (result: InfiniteQueryObserverResult<TData, TError>) => void;
/**
* 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
* ```ts
* 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))
* ```
*/
export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey> {
subscribe: Subscribable<InfiniteQueryObserverListener<TData, TError>>['subscribe'];
getCurrentResult: ReplaceReturnType<QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>['getCurrentResult'], InfiniteQueryObserverResult<TData, TError>>;
protected fetch: ReplaceReturnType<QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>['fetch'], Promise<InfiniteQueryObserverResult<TData, TError>>>;
constructor(client: QueryClient, options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>);
protected bindMethods(): void;
/**
* 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.
* @param options - The new infinite query observer options.
*/
setOptions(options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): void;
/**
* The infinite-query counterpart of {@link 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.
* @param options - The defaulted infinite query observer options to compute the result for.
* @returns The result for the given options.
*/
getOptimisticResult(options: DefaultedInfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
/**
* 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`.
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
* and `throwOnError` to `true` to reject when the fetch fails.
* @returns A promise that resolves with the result after the next page is fetched. With
* `cancelRefetch: false`, a running fetch is reused instead, so the next page may not be fetched.
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
* @example
* ```ts
* const { hasNextPage } = observer.getCurrentResult()
*
* if (hasNextPage) {
* await observer.fetchNextPage()
* }
* ```
*/
fetchNextPage(options?: FetchNextPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
/**
* 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`.
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
* and `throwOnError` to `true` to reject when the fetch fails.
* @returns A promise that resolves with the result after the previous page is fetched. With
* `cancelRefetch: false`, a running fetch is reused instead, so the previous page may not be fetched.
* @see {@link InfiniteQueryObserver#fetchNextPage}
* @example
* ```ts
* const { hasPreviousPage } = observer.getCurrentResult()
*
* if (hasPreviousPage) {
* await observer.fetchPreviousPage()
* }
* ```
*/
fetchPreviousPage(options?: FetchPreviousPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
protected createResult(query: Query<TQueryFnData, TError, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>, options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
}
type ReplaceReturnType<TFunction extends (...args: Array<any>) => unknown, TReturn> = (...args: Parameters<TFunction>) => TReturn;
//#endregion
//# sourceMappingURL=infiniteQueryObserver.d.ts.map