Skip to main content

useSuspenseInfiniteQuery

The useSuspenseInfiniteQuery 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 queries
boolean | (error: TError) => boolean
default:"true"
Set to true to throw errors to the nearest error boundary
QueryClient
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 queries
FetchStatus
The fetch status of the query: 'fetching', 'paused', or 'idle'
true
Always true for suspense queries
false
Always false for suspense queries
false
Always false for suspense queries
boolean
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

  • skipToken cannot be used with useSuspenseInfiniteQuery. If you need conditional fetching, use useInfiniteQuery instead.
  • The component will suspend until the initial data is loaded.
  • Errors are thrown to the nearest error boundary by default.
  • The enabled option is always set to true and cannot be disabled.