UNPKG

@tanstack/react-db

Version:

React integration for @tanstack/db

43 lines (42 loc) 2.61 kB
import { LiveQueryKey, useLiveQuery } from './useLiveQuery.js'; import { Collection, Context, DbClient, InferResultType, InitialQueryBuilder, NonSingleResult, QueryBuilder } from '@tanstack/db'; export type UseLiveInfiniteQueryConfig<TContext extends Context> = { /** * Explicit identity for queries that contain opaque functional variants or * are hot enough that deriving identity from structured IR is too expensive. * Structured queries should omit this so DB can derive identity directly. */ queryKey?: LiveQueryKey; /** Override the nearest DbProvider for this query. */ client?: DbClient; pageSize?: number; initialPageParam?: number; /** * @deprecated This callback is not used by the current implementation. * Pagination is determined internally via a peek-ahead strategy. * Provided for API compatibility with TanStack Query conventions. */ getNextPageParam?: (lastPage: Array<InferResultType<TContext>[number]>, allPages: Array<Array<InferResultType<TContext>[number]>>, lastPageParam: number, allPageParams: Array<number>) => number | undefined; }; export type UseLiveInfiniteQueryReturn<TContext extends Context> = Omit<ReturnType<typeof useLiveQuery<TContext>>, `data`> & { data: InferResultType<TContext>; pages: Array<Array<InferResultType<TContext>[number]>>; pageParams: Array<number>; fetchNextPage: () => Promise<void>; hasNextPage: boolean; isFetchingNextPage: boolean; error: unknown; }; /** * Create an infinite query using a query function with live updates. * * Uses `utils.setWindow()` to dynamically adjust the limit/offset window * without recreating the live query collection on each page change. * * @param queryFn - Query function that defines what data to fetch. Must include `.orderBy()` for setWindow to work. * @param config - Configuration including pageSize and getNextPageParam * @param deps - Deprecated array of dependencies that trigger query re-execution when changed * @returns Object with pages, data, and pagination controls */ export declare function useLiveInfiniteQuery<TResult extends object, TKey extends string | number, TUtils extends Record<string, any>>(liveQueryCollection: Collection<TResult, TKey, TUtils> & NonSingleResult, config: UseLiveInfiniteQueryConfig<any>): UseLiveInfiniteQueryReturn<any>; export declare function useLiveInfiniteQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext>, config: UseLiveInfiniteQueryConfig<TContext>, deps?: Array<unknown>): UseLiveInfiniteQueryReturn<TContext>;