useLiveInfiniteQuery
Reads an ordered
@hyper-fetch/db
query page by page, as a window that
fetchNextPage
widens. Rows the db already
holds show at once, and the query's loader loads more only when the window runs past them, so the UI's page size is
independent of the backend's. The window stays live: inserts shift rows across pages, and deletes pull the next row
in.
Like
useLiveQuery
, it takes no dependency array. The same query keeps its loaded pages across renders, and a
different query or page size starts again from the first page. The query must have
orderBy
.
import { useLiveInfiniteQuery } from "@hyper-fetch/react"
Usage
const { pages, hasNextPage, fetchNextPage, isFetchingNextPage } = useLiveInfiniteQuery(
db.post.where((post) => eq(post.teamId, teamId)).orderBy((post) => post.createdAt, "desc"),
{ pageSize: 20 },
);
Parameters
useLiveInfiniteQuery<Query>(query: Query & InfiniteQueryCheck<Query>, options: InfiniteQueryOptions)
| Name | Type | Description |
|---|---|---|
| query | | |
| options | |
Returns
type UseLiveInfiniteQueryReturnType<Query> = InfiniteQueryState<ExtractQueryResult<Query>> & { fetchNextPage: () => Promise<void>; refetch: () => Promise<void> };
| Name | Type | Description |
|---|---|---|
| isFetchingNextPage | | Whether more rows are loading to fill the window after
|
| pages | |
|
| fetchNextPage | | Widens the window by one page, loading from the backend only when the db holds too few rows |
| refetch | | Loads the query again from its first page |
