The useSuspenseQuery hook is a specialized version of useQuery designed for React Suspense. It always suspends while fetching and throws errors to error boundaries, providing a more streamlined type signature.
Import
Signature
Parameters
The query options object. A unique key for the query. Must be an array. queryFn QueryFunction<TQueryFnData, TQueryKey>
required
The function that the query will use to request data. Cannot be skipToken. staleTime number | 'static' | ((query: Query) => number | 'static')
default: "0"
The time in milliseconds after data is considered stale.
The time in milliseconds that unused/inactive cache data remains in memory.
refetchInterval number | false | ((query: Query) => number | false)
default: "false"
If set to a number, the query will continuously refetch at this frequency.
refetchIntervalInBackground If true, refetch will continue while the tab is in the background.
refetchOnWindowFocus boolean | 'always' | ((query: Query) => boolean | 'always')
default: "true"
Refetch on window focus behavior.
refetchOnReconnect boolean | 'always' | ((query: Query) => boolean | 'always')
default: "true"
Refetch on reconnect behavior.
refetchOnMount boolean | 'always' | ((query: Query) => boolean | 'always')
default: "true"
Refetch on mount behavior.
retry boolean | number | ((failureCount: number, error: TError) => boolean)
default: "3"
Retry configuration for failed queries.
retryDelay number | ((failureCount: number, error: TError) => number)
Delay between retries in milliseconds.
select (data: TQueryData) => TData
Transform or select part of the data. networkMode 'online' | 'always' | 'offlineFirst'
default: "'online'"
Network mode configuration.
If false, the query will not retry on mount if it contains an error.
notifyOnChangeProps Array<keyof UseSuspenseQueryResult> | 'all'
Properties to track for re-rendering.
Override the default QueryClient.
The following options are NOT available in useSuspenseQuery because they are automatically set:
enabled - Always true
suspense - Always true
throwOnError - Always throws errors to error boundaries
placeholderData - Not supported
Returns
UseSuspenseQueryResult<TData, TError> The query result object. Data is always defined (never undefined). The last successfully resolved data for the query. Always defined (never undefined).
The error object for the query. Always null when data is available.
Always 'success' because the query suspends on pending and throws on error.
fetchStatus 'fetching' | 'paused' | 'idle'
The fetch status of the query.
Always false because the query suspends during pending state.
Always false because the query suspends during loading state.
true if the query is currently fetching (background refetch).
Always true when the component renders.
Always false because errors are thrown to error boundaries.
true if a background refetch is in progress.
true if the data is stale.
true if the query failed during a background refetch.
Timestamp of when the query most recently returned success.
Timestamp of when the query most recently returned an error.
The failure count for the query.
The failure reason for the query retry.
refetch (options?: RefetchOptions) => Promise<UseSuspenseQueryResult>
Function to manually refetch the query.
Examples
Basic Usage
With Error Boundary
Multiple Suspense Queries
With Select
Nested Suspense Boundaries
Notes
useSuspenseQuery requires React’s Suspense and Error Boundary to be set up in parent components.
The data property is always defined (never undefined) when the component renders, providing better type safety.
Errors are automatically thrown to the nearest error boundary, so you don’t need to handle error states manually.
The skipToken cannot be used with useSuspenseQuery. Use regular useQuery with enabled: false if you need conditional fetching.