Open History to see the last commit
1---
2id: overview
3title: Overview
4---
5β
6> IMPORTANT: The `@tanstack/lit-query` package is currently experimental and v0.1. Expect the Lit adapter API and docs to keep evolving. If you use it in production while it is early, pin the package to a patch version and upgrade deliberately.
7β
8The `@tanstack/lit-query` package is the Lit adapter for TanStack Query. It gives Lit applications reactive controller APIs for fetching, caching, synchronizing, and updating server state.
9β
10TanStack Query manages server state: data that is owned by a remote system, fetched asynchronously, shared across screens, and potentially changed by someone else at any time. It handles caching, request deduplication, stale data, background refetching, mutations, invalidation, pagination, and garbage collection.
11β
12Lit Query exposes those features through [Lit reactive controllers](https://lit.dev/docs/composition/controllers/). A Lit reactive controller is attached to a `ReactiveControllerHost`, usually a `LitElement`. Lit Query controllers subscribe to the `QueryClient`, request host updates when results change, and are cleaned up with the host lifecycle.
13β
14## Core APIs
15β
16Most Lit applications use these APIs:
17β
18- [`QueryClientProvider`](./reference/classes/QueryClientProvider.md) to provide a `QueryClient` through Lit context
19- [`createQueryController`](./reference/functions/createQueryController.md) for queries
20- [`createQueriesController`](./reference/functions/createQueriesController.md) for dynamic parallel queries
21- [`createMutationController`](./reference/functions/createMutationController.md) for mutations
22- [`createInfiniteQueryController`](./reference/functions/createInfiniteQueryController.md) for infinite queries
23- [`useIsFetching`](./reference/functions/useIsFetching.md), [`useIsMutating`](./reference/functions/useIsMutating.md), and [`useMutationState`](./reference/functions/useMutationState.md) for cache state indicators
24β
25The adapter also re-exports TanStack Query Core APIs from `@tanstack/lit-query`, so examples in the Lit docs use `@tanstack/lit-query` as the user-facing import path.
26β
27## A First Query
28β
29```ts
30import { LitElement, html } from 'lit'
31import {
32 QueryClient,
33 QueryClientProvider,
34 createQueryController,
35} from '@tanstack/lit-query'
36β
37const queryClient = new QueryClient()
38β
39class AppQueryProvider extends QueryClientProvider {
40 constructor() {
41 super()
42 this.client = queryClient
43 }
44}
45β
46customElements.define('app-query-provider', AppQueryProvider)
47β
48class RepoStats extends LitElement {
49 private readonly repo = createQueryController(this, {
50 queryKey: ['repoData'],
51 queryFn: async () => {
52 const response = await fetch(
53 'https://api.github.com/repos/TanStack/query',
54 )
55 if (!response.ok) throw new Error('Failed to fetch repo data')
56 return response.json() as Promise<{
57 name: string
58 description: string
59 stargazers_count: number
60 }>
61 },
62 })
63β
64 render() {
65 const query = this.repo()
66β
67 if (query.isPending) return html`Loading...`
68 if (query.isError) return html`Error: ${query.error.message}`
69β
70 return html`
71 <h1>${query.data.name}</h1>
72 <p>${query.data.description}</p>
73 <strong>${query.data.stargazers_count} stars</strong>
74 `
75 }
76}
77β
78customElements.define('repo-stats', RepoStats)
79```
80β
81Render the provider above your query consumers:
82β
83```html
84<app-query-provider>
85 <repo-stats></repo-stats>
86</app-query-provider>
87```
88β
89## Status Notes
90β
91Lit Devtools are not available yet. Use the cache APIs and the generated API reference while the adapter matures.
92β
93Start with [Installation](./installation.md), then [Quick Start](./quick-start.md), and use the [Reactive Controllers vs Hooks](./guides/reactive-controllers-vs-hooks.md) guide if you are coming from React Query.