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 |
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
Background Refetching
Pages are refreshed in the background to stay current
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
- Limit pages — Use maxPages to control memory usage