Skip to main content
The useQuery hook is the primary way to fetch data in TanStack Query. It manages the lifecycle of a query, including caching, background updates, and stale data management.

Import

Signature

Parameters

object
required
The query options object.
QueryClient
Use this to override the default QueryClient.

Returns

object
The query result object.

Examples

Basic Usage

With Query Key Variables

Dependent Query

With Select Transform

With Type Safety

Notes

The query will automatically execute when the component mounts and whenever the queryKey changes, unless enabled is set to false.
If initialData is provided, the query will return status: 'success' immediately and data will be defined.
For queries with suspense: true, use useSuspenseQuery instead for better type safety.