useSuspenseInfiniteQuery
TheuseSuspenseInfiniteQuery hook is a Suspense-enabled version of useInfiniteQuery. It suspends rendering until data is available and always returns data (never undefined).
Import
Signature
Type Parameters
The type of data returned by the query function for each page
The type of error that can be thrown by the query function
The type of data returned by the select function (if provided)
The type of the query key
The type of the page parameter
Parameters
Configuration options for the infinite query. All options from
useInfiniteQuery are supported, with the following differences:A unique key for the query. Must be an array.
The function that will be called to fetch data. Cannot use
skipToken with Suspense queries.The default page param to use when fetching the first page
getNextPageParam
(lastPage: TQueryFnData, allPages: TQueryFnData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined | null
required
Function that returns the next page parameter. Return
undefined or null to indicate there are no more pages.getPreviousPageParam
(firstPage: TQueryFnData, allPages: TQueryFnData[], firstPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined | null
Function that returns the previous page parameter. Return
undefined or null to indicate there are no previous pages.This option is always set to
true for suspense queriesSet to
true to throw errors to the nearest error boundaryOptional QueryClient instance to use. If not provided, the context client is used.
Returns
The data returned by the query function. Always defined (never undefined) for suspense queries.
Always
null for suspense queries (errors are thrown to error boundaries)Always
'success' for suspense queriesThe fetch status of the query:
'fetching', 'paused', or 'idle'Always
true for suspense queriesAlways
false for suspense queriesAlways
false for suspense queriesWhether the query is currently fetching
Whether there is a next page available
Whether there is a previous page available
Function to fetch the next page
Function to fetch the previous page
Whether the query is currently fetching the next page
Whether the query is currently fetching the previous page
Function to manually refetch the query
Examples
Basic Usage
With Error Boundary
Notes
skipTokencannot be used withuseSuspenseInfiniteQuery. If you need conditional fetching, useuseInfiniteQueryinstead.- The component will suspend until the initial data is loaded.
- Errors are thrown to the nearest error boundary by default.
- The
enabledoption is always set totrueand cannot be disabled.