Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TanStack · Hook

useSuspenseQuery

useSuspenseQuery fetches query data through React Suspense instead of exposing a disabled or loading state. It returns a useQuery-like result with data guaranteed to be defined.

Since
5

How it works

useSuspenseQuery is the Suspense-specific form of useQuery. It accepts query options and an optional QueryClient, suspends rendering while required data loads, and returns a result whose data is defined; loading and error handling are delegated to Suspense and error boundaries.

Syntax

function useSuspenseQuery<TQueryFnData, TError, TData, TQueryKey>(options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseSuspenseQueryResult<TData, TError>;

Parameters

NameTypeDescription
optionsUseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>Configuration for the query, using UseSuspenseQueryOptions; it follows useQuery options except for throwOnError, enabled, and placeholderData.
queryClientQueryClientOptional client used to access the query cache and configuration.

Returns

UseSuspenseQueryResult<TData, TError>: the useQuery result shape with defined data, no isPlaceholderData, and status limited to success or error.

Key points

  • Configure the hook with normal query options, excluding throwOnError, enabled, and placeholderData.
  • Suspense and error boundaries take responsibility for loading and error presentation instead of ordinary query-state branches.
  • After the component renders, data can be used without an undefined check.
  • The result status is narrowed to success or error, with corresponding derived flags.
  • A disabled query state is unsupported, so skipToken is not valid as the query function.

Common mistakes

  • A query function is required unless a default query function exists; skipToken cannot disable this hook.
  • Do not depend on cancellation for an in-flight request.

Example: Suspense-backed query

import { Suspense } from 'react'
import { useSuspenseQuery } from '@tanstack/react-query'

function Todos() {
  const { data } = useSuspenseQuery({
    queryKey: ['todos'],
    queryFn: async () => {
      const response = await fetch('/api/todos')
      if (!response.ok) throw new Error('Request failed')
      return response.json() as Promise<{ id: number; title: string }[]>
    },
  })

  return <ul>{data.map(todo => <li key={todo.id}>{todo.title}</li>)}</ul>
}

export function App() {
  return <Suspense fallback={<p>Loading…</p>}><Todos /></Suspense>
}

Fetches todos while React Suspense supplies the loading boundary; the hook returns defined data when Todos renders.

When to use it

Suspense-driven loading

A component needs fetched data before it can render its main content.

Boundary-based errors

An application uses React error boundaries for query failures.

Server rendering and streaming

A TanStack Router application needs query data involved in SSR or streaming.

Interview questions

QWhich useQuery options are unavailable?

It has the same options as useQuery except throwOnError, enabled, and placeholderData. Suspense controls loading, while errors are handled through an error boundary or explicit error throwing.

Follow-up: How does its result differ from useQuery? Data is guaranteed to be defined, isPlaceholderData is absent, and status is success or error.

QHow should a component handle loading?

The hook suspends when data is needed, so the component should be rendered under a React Suspense boundary. The boundary supplies the fallback while the query resolves.

Follow-up: What happens to loading flags? The Suspense boundary replaces the component's loading-state handling rather than requiring an enabled/loading branch.

QWhat does the hook return?

Its signature accepts UseSuspenseQueryOptions and an optional QueryClient, and returns UseSuspenseQueryResult. The returned data has type TData and is guaranteed to be defined.

Follow-up: Can the query be disabled with skipToken? No; Suspense hooks cannot represent a disabled state, so a query function must be available.

  • useQuery
  • useSuspenseInfiniteQuery
  • useSuspenseQueries
  • QueryClient
  • UseSuspenseQueryOptions
  • UseSuspenseQueryResult

Source: useSuspenseQuery | TanStack Query React Docs. Checked 2026-10-15.