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
type
The type of data returned by the query function for each page
type
default:"DefaultError"
The type of error that can be thrown by the query function
type
default:"InfiniteData<TQueryFnData>"
The type of data returned by the select function (if provided)
type
default:"QueryKey"
The type of the query key
type
default:"unknown"
The type of the page parameter
Parameters
UseSuspenseInfiniteQueryOptions
required
Configuration options for the infinite query. All options from
useInfiniteQuery are supported, with the following differences:TQueryKey
required
A unique key for the query. Must be an array.
QueryFunction<TQueryFnData, TQueryKey>
required
The function that will be called to fetch data. Cannot use
skipToken with Suspense queries.TPageParam
required
The default page param to use when fetching the first page
(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.(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.boolean
default:"true"
This option is always set to
true for suspense queriesboolean | (error: TError) => boolean
default:"true"
Set to
true to throw errors to the nearest error boundaryQueryClient
Optional QueryClient instance to use. If not provided, the context client is used.
Returns
TData
required
The data returned by the query function. Always defined (never undefined) for suspense queries.
null
Always
null for suspense queries (errors are thrown to error boundaries)'success'
Always
'success' for suspense queriesFetchStatus
The fetch status of the query:
'fetching', 'paused', or 'idle'true
Always
true for suspense queriesfalse
Always
false for suspense queriesfalse
Always
false for suspense queriesboolean
Whether the query is currently fetching
boolean
Whether there is a next page available
boolean
Whether there is a previous page available
(options?: FetchNextPageOptions) => Promise<InfiniteQueryObserverResult>
Function to fetch the next page
(options?: FetchPreviousPageOptions) => Promise<InfiniteQueryObserverResult>
Function to fetch the previous page
boolean
Whether the query is currently fetching the next page
boolean
Whether the query is currently fetching the previous page
(options?: RefetchOptions) => Promise<QueryObserverResult>
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.