Infinite Query
Learn about SoulCache's infinite query for paginated data
Infinite Query
Infinite queries handle paginated data fetching with automatic cursor management.
Import
Constructor
Types
InfiniteQueryOptions<TData, TPageParam>
InfiniteQueryState<TData>
InfiniteQueryPage<TData>
Properties
| Property | Type | Description |
|---|---|---|
id | string | Unique query ID |
queryKey | readonly unknown[] | Query cache key |
data | TData[] | Flat array of all page data |
state | InfiniteQueryState<TData> | Snapshot of the current query state |
isLoading | boolean | Whether the initial fetch is in progress (no data yet) |
isFetching | boolean | Whether any fetch (initial, next, or previous) is in progress |
hasNextPage | boolean | Whether next page is available |
hasPreviousPage | boolean | Whether previous page is available |
isFetchingNextPage | boolean | Whether next page is fetching |
isFetchingPreviousPage | boolean | Whether previous page is fetching |
pageCount | number | Number of loaded pages |
isDestroyed | boolean | Whether query is destroyed |
Methods
fetch()
Fetch all pages.
fetchNextPage()
Fetch the next page. Returns true if a new page was fetched.
fetchPreviousPage()
Fetch the previous page. Returns true if a new page was fetched.
subscribe(listener)
Subscribe to state changes.
cancel()
Cancel any in-flight fetch.
reset()
Reset to initial state.
destroy()
Destroy the query and cleanup resources.
Usage
Features
Automatic Cursor Management
Cursor tracking is handled automatically between pages
Bidirectional Pagination
Support for both forward and backward pagination
Bounded Page Window
Up to 50 pages retained by default to control memory
Max Pages Limit
Control memory usage by limiting number of kept pages
Best Practices
Infinite Query Guidelines
- Use stable cursors — Ensure consistent pagination across refetches
- Handle loading states — Show feedback during page fetches
- Implement error boundaries — Handle fetch failures gracefully
- Understand the page cap — Up to 50 pages are retained by default; oldest
pages are evicted beyond the cap. Set
maxPages: Infinityto keep every page, or a smaller value to bound memory harder.