Skip to main content
Version: v10.0.0

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
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)
Parameters
NameTypeDescription
query
Query & InfiniteQueryCheck<Query>
options
InfiniteQueryOptions

Returns​

type UseLiveInfiniteQueryReturnType<Query> = InfiniteQueryState<ExtractQueryResult<Query>> & { fetchNextPage: () => Promise<void>; refetch: () => Promise<void> };
useLiveInfiniteQuery
NameTypeDescription
isFetchingNextPage
boolean

Whether more rows are loading to fill the window after fetchNextPage

pages
Item[][]

data split into pages of pageSize

fetchNextPage
() => Promise<void>

Widens the window by one page, loading from the backend only when the db holds too few rows

refetch
() => Promise<void>

Loads the query again from its first page