Installation
Get started with Solid Query by installing the package and setting up your application.Prerequisites
Solid Query requires SolidJS 1.6.0 or higher.Package Installation
Solid Query follows semantic versioning. The current version is 5.90.23.
Basic Setup
After installation, set up theQueryClientProvider in your application root:
import { render } from 'solid-js/web'
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
const queryClient = new QueryClient()
function App() {
return (
<QueryClientProvider client={queryClient}>
<div>
<h1>My App</h1>
{/* Your application components */}
</div>
</QueryClientProvider>
)
}
render(() => <App />, document.getElementById('root')!)
import { useQuery } from '@tanstack/solid-query'
function TodoList() {
const todosQuery = useQuery(() => ({
queryKey: ['todos'],
queryFn: async () => {
const response = await fetch('https://api.example.com/todos')
return response.json()
},
}))
return (
<div>
<Show when={todosQuery.data}>
{(todos) => (
<For each={todos()}>
{(todo) => <li>{todo.title}</li>}
</For>
)}
</Show>
</div>
)
}
Configuration Options
Customize theQueryClient with default options:
Common Configuration Options
These are the most commonly used configuration options. See the full API reference for all available options.
| Option | Type | Default | Description |
|---|---|---|---|
staleTime | number | 0 | Time in milliseconds before data is considered stale |
gcTime | number | 5 * 60 * 1000 | Time before inactive queries are garbage collected |
refetchOnWindowFocus | boolean | true | Refetch queries when window regains focus |
refetchOnReconnect | boolean | true | Refetch queries when network reconnects |
retry | number | boolean | 3 | Number of retry attempts for failed queries |
retryDelay | function | exponential | Delay between retry attempts |
Server-Side Rendering Setup
For SSR applications, create a newQueryClient instance per request:
DevTools Installation (Optional)
Install the DevTools package for development debugging:TypeScript Setup
Solid Query is written in TypeScript and provides full type safety out of the box. No additional configuration is needed, but you can enhance type inference:Bundle Size
Solid Query is designed to be lightweight:- @tanstack/solid-query: ~15kb min+gzip
- @tanstack/solid-query-devtools: ~25kb min+gzip (dev only)
The exact bundle size depends on your bundler and tree-shaking configuration. The package is fully tree-shakeable.
Version Compatibility
Solid Query is tested against multiple TypeScript versions:- TypeScript 5.0+
- TypeScript 5.1+
- TypeScript 5.2+
- TypeScript 5.3+
- TypeScript 5.4+
- TypeScript 5.5+
- TypeScript 5.6+
- TypeScript 5.7+ (latest)
Next Steps
Quick Start
Build your first application with Solid Query
Overview
Learn about core concepts and features