Installation
TanStack Svelte Query requires Svelte 5.25.0 or later.
Setup
Wrap your application withQueryClientProvider:
Core Functions
createQuery
Fetch and cache data withcreateQuery:
Reactive Query Keys
Svelte Query works seamlessly with Svelte’s reactive statements:createMutation
Perform side effects with mutations:createInfiniteQuery
Implement infinite scrolling:Svelte 5 Runes Support
Using $state Rune
Svelte Query integrates seamlessly with Svelte 5’s runes:Using $derived Rune
Using $effect Rune
Svelte Query’s internal implementation uses Svelte 5 runes (
$state, $derived, $effect), providing optimal reactivity and performance.Store API
Accessing Query State
Query results are Svelte stores with a special.value property:
Derived Stores
Create derived stores from query results:Advanced Features
createQueries
Execute multiple queries in parallel:Query Options Factory
useMutationState
Track all mutations globally:useIsFetching
Show a global loading indicator:HydrationBoundary
For SSR with SvelteKit:TypeScript
Full TypeScript support:Context API
Access the QueryClient in nested components:Svelte-Specific Patterns
Reactive Queries with Stores
Component Props Reactivity
Migration from Svelte 4
Svelte 5 brings significant changes to reactivity:- Svelte 5 (Runes)
- Svelte 4 (Reactive Statements)