Skip to main content
Fetch and cache data with the useQuery composable. It returns a reactive query result that automatically updates when dependencies change.

Signature

Parameters

UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>
required
Configuration options for the query. Can be a reactive ref or getter function.
QueryClient
Custom QueryClient instance. If not provided, uses the client from context.

Returns

object
Reactive refs containing query state and methods.

Type Parameters

  • TQueryFnData - Type returned by the query function
  • TError - Type of error (defaults to DefaultError)
  • TData - Type of data returned (defaults to TQueryFnData)
  • TQueryKey - Type of the query key (defaults to QueryKey)

Examples

Basic Usage

Reactive Query Keys

With TypeScript

Conditional Fetching

With Select

Shallow Reactivity