File: overview.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
Solid
Version
v4
Search...
+ K
Menu
Getting Started
API Reference
ESLint
Framework
Solid
Version
v4
Menu
Getting Started
API Reference
ESLint
On this page
Copy Markdown
The @tanstack/solid-query package provides a 1st-class API for using TanStack Query with SolidJS.
tsx
import { QueryClient, QueryClientProvider, createQuery } from '@tanstack/solid-query'
import { Switch, Match, For } from 'solid-js'
const queryClient = new QueryClient()
function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
return (
<div>
<Switch>
<Match when={query.isLoading}>
<p>Loading...</p>
</Match>
<Match when={query.isError}>
<p>Error: {query.error.message}</p>
</Match>
<Match when={query.isSuccess}>
<For each={query.data}>
{(todo) => <p>{todo.title}</p>}
</For>
</Match>
</Switch>
</div>
)
}
function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
import { QueryClient, QueryClientProvider, createQuery } from '@tanstack/solid-query'
import { Switch, Match, For } from 'solid-js'
const queryClient = new QueryClient()
function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
return (
<div>
<Switch>
<Match when={query.isLoading}>
<p>Loading...</p>
</Match>
<Match when={query.isError}>
<p>Error: {query.error.message}</p>
</Match>
<Match when={query.isSuccess}>
<For each={query.data}>
{(todo) => <p>{todo.title}</p>}
</For>
</Match>
</Switch>
</div>
)
}
function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
Available Functions
-------------------
Solid Query offers useful primitives and functions that will make managing server state in SolidJS apps easier.
Solid Query offers an API similar to React Query, but there are some key differences to be mindful of.
tsx
// β react version
useQuery(["todos", todo], fetchTodos)
// β
solid version
createQuery(() => ["todos", todo()], fetchTodos)
// β react version
useQuery(["todos", todo], fetchTodos)
// β
solid version
createQuery(() => ["todos", todo()], fetchTodos)
tsx
import { For, Suspense } from 'solid-js'
function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
return (
<div>
{/* β
Will trigger loading fallback, data accessed in a suspense context. */}
<Suspense fallback={"Loading..."}>
<For each={query.data}>{(todo) => <div>{todo.title}</div>}</For>
</Suspense>
{/* β Will not trigger loading fallback, data not accessed in a suspense context. */}
<For each={query.data}>{(todo) => <div>{todo.title}</div>}</For>
</div>
)
}
import { For, Suspense } from 'solid-js'
function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
return (
<div>
{/* β
Will trigger loading fallback, data accessed in a suspense context. */}
<Suspense fallback={"Loading..."}>
<For each={query.data}>{(todo) => <div>{todo.title}</div>}</For>
</Suspense>
{/* β Will not trigger loading fallback, data not accessed in a suspense context. */}
<For each={query.data}>{(todo) => <div>{todo.title}</div>}</For>
</div>
)
}
tsx
import { QueryClient, QueryClientProvider, createQuery } from '@tanstack/solid-query'
import { Match, Switch } from 'solid-js'
const queryClient = new QueryClient()
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
function Example() {
// β react version -- supports destructing outside reactive context
// const { isLoading, error, data } = useQuery(['repoData'], () =>
// fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
// res.json()
// )
// )
// β
solid version -- does not support destructuring outside reactive context
const query = createQuery(
() => ['repoData'],
() =>
fetch('https://api.github.com/repos/tannerlinsley/react-query').then(
(res) => res.json(),
),
)
// β
access query properties in JSX reactive context
return (
<Switch>
<Match when={query.isLoading}>Loading...</Match>
<Match when={query.isError}>Error: {query.error.message}</Match>
<Match when={query.isSuccess}>
<div>
<h1>{query.data.name}</h1>
<p>{query.data.description}</p>
<strong>π {query.data.subscribers_count}</strong>{' '}
<strong>β¨ {query.data.stargazers_count}</strong>{' '}
<strong>π΄ {query.data.forks_count}</strong>
</div>
</Match>
</Switch>
)
}
import { QueryClient, QueryClientProvider, createQuery } from '@tanstack/solid-query'
import { Match, Switch } from 'solid-js'
const queryClient = new QueryClient()
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
function Example() {
// β react version -- supports destructing outside reactive context
// const { isLoading, error, data } = useQuery(['repoData'], () =>
// fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
// res.json()
// )
// )
// β
solid version -- does not support destructuring outside reactive context
const query = createQuery(
() => ['repoData'],
() =>
fetch('https://api.github.com/repos/tannerlinsley/react-query').then(
(res) => res.json(),
),
)
// β
access query properties in JSX reactive context
return (
<Switch>
<Match when={query.isLoading}>Loading...</Match>
<Match when={query.isError}>Error: {query.error.message}</Match>
<Match when={query.isSuccess}>
<div>
<h1>{query.data.name}</h1>
<p>{query.data.description}</p>
<strong>π {query.data.subscribers_count}</strong>{' '}
<strong>β¨ {query.data.stargazers_count}</strong>{' '}
<strong>π΄ {query.data.forks_count}</strong>
</div>
</Match>
</Switch>
)
}
tsx
import {
QueryClient,
QueryClientProvider,
createQuery,
} from '@tanstack/solid-query'
import { createSignal, For } from 'solid-js'
const queryClient = new QueryClient()
function Example() {
const [enabled, setEnabled] = createSignal(false)
const query = createQuery(() => ['todos'], fetchTodos, {
// β passing a signal directly is not reactive
// enabled: enabled(),
// β
passing a function that returns a signal is reactive
get enabled() {
return enabled()
},
})
return (
<div>
<Switch>
<Match when={query.isLoading}>
<p>Loading...</p>
</Match>
<Match when={query.isError}>
<p>Error: {query.error.message}</p>
</Match>
<Match when={query.isSuccess}>
<For each={query.data}>
{(todo) => <p>{todo.title}</p>}
</For>
</Match>
</Switch>
<button onClick={() => setEnabled(!enabled())}>Toggle enabled</button>
</div>
)
}
function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
import {
QueryClient,
QueryClientProvider,
createQuery,
} from '@tanstack/solid-query'
import { createSignal, For } from 'solid-js'
const queryClient = new QueryClient()
function Example() {
const [enabled, setEnabled] = createSignal(false)
const query = createQuery(() => ['todos'], fetchTodos, {
// β passing a signal directly is not reactive
// enabled: enabled(),
// β
passing a function that returns a signal is reactive
get enabled() {
return enabled()
},
})
return (
<div>
<Switch>
<Match when={query.isLoading}>
<p>Loading...</p>
</Match>
<Match when={query.isError}>
<p>Error: {query.error.message}</p>
</Match>
<Match when={query.isSuccess}>
<For each={query.data}>
{(todo) => <p>{todo.title}</p>}
</For>
</Match>
</Switch>
<button onClick={() => setEnabled(!enabled())}>Toggle enabled</button>
</div>
)
}
function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
Errors can be caught and reset using SolidJS' native ErrorBoundary component. QueryErrorResetBoundary is not needed with Solid Query
Since Property tracking is handled through Solid's fine grained reactivity, options like notifyOnChangeProps are not needed
[###### Want to Skip the Docs?
Query.gg - The Official React Query Course
\
βIf youβre serious about *really* understanding React Query, thereβs no better way than with query.ggββTanner Linsley
Learn More](https://query.gg/?s=tanstack)
You are currently reading v4 docs. Redirect to latest version?
Latest Hide
