Skip to main content
Fetch and cache data with the createQuery function. It returns a reactive query result that automatically updates when dependencies change in Svelte 5’s runes mode.

Signature

Parameters

Accessor<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>>
required
A function (accessor) returning query configuration options.
Accessor<QueryClient>
Accessor returning a custom QueryClient instance. If not provided, uses the client from context.

Returns

object
Reactive query state accessible via Svelte runes.

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 (Svelte 5 Runes)

Reactive Query Keys

With TypeScript

Conditional Fetching

With Select

Dependent Queries

Initial Data

Polling/Refetch Interval

Manual Refetch

Error Handling

Multiple Reactive Dependencies

With Loading States

Notes

Svelte Query uses Svelte 5’s runes mode. The options parameter must be an accessor (function) to track reactive dependencies.
Access query state properties directly (e.g., query.data, query.isLoading) without needing to use $state or stores.
Make sure to use Svelte 5 with runes mode enabled. Svelte Query v5+ requires Svelte 5.