mirror of
https://github.com/TanStack/query.git
synced 2026-11-18 19:33:22 +00:00
`isLoading` is a deprecated alias for `isPending && isFetching` and is scheduled for removal in the next major version. The overview example shows a standard (always-enabled) query, so `isPending` is the correct flag. All other framework overview docs (React, Vue, Angular, Lit, Preact) already use `isPending`. Note: `isLoading` is intentionally retained in disabling-queries guides where it is the right flag for disabled/lazy queries. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1.8 KiB
1.8 KiB
| id | title |
|---|---|
| overview | Overview |
The @tanstack/svelte-query package offers a 1st-class API for using TanStack Query via Svelte.
Migrating from stores to the runes syntax? See the migration guide.
Example
Include the QueryClientProvider near the root of your project:
<script lang="ts">
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
import Example from './lib/Example.svelte'
const queryClient = new QueryClient()
</script>
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
Then call any function (e.g. createQuery) from any component:
<script lang="ts">
import { createQuery } from '@tanstack/svelte-query'
const query = createQuery(() => ({
queryKey: ['todos'],
queryFn: () => fetchTodos(),
}))
</script>
<div>
{#if query.isPending}
<p>Loading...</p>
{:else if query.isError}
<p>Error: {query.error.message}</p>
{:else if query.isSuccess}
{#each query.data as todo}
<p>{todo.title}</p>
{/each}
{/if}
</div>
SvelteKit
If you are using SvelteKit, please have a look at SSR & SvelteKit.
Available Functions
Svelte Query offers useful functions and components that will make managing server state in Svelte apps easier.
createQuerycreateQueriescreateInfiniteQuerycreateMutationuseQueryClientuseIsFetchinguseIsMutatinguseMutationStateuseIsRestoringuseHydrate<QueryClientProvider><HydrationBoundary>
Important Differences between Svelte Query & React Query
Svelte Query offers an API similar to React Query, but there are some key differences to be mindful of.
- The arguments to the
create*functions must be wrapped in a function to preserve reactivity.