Open History to see the last commit
1---
2id: installation
3title: Installation
4---
5β
6> IMPORTANT: The Lit adapter is currently experimental and v0.1. Pin exact versions if you need extra release stability while the API is early.
7β
8Install Lit Query with Lit and TanStack Query Core:
9β
10```bash
11npm i @tanstack/lit-query @tanstack/query-core lit
12```
13β
14or
15β
16```bash
17pnpm add @tanstack/lit-query @tanstack/query-core lit
18```
19β
20or
21β
22```bash
23yarn add @tanstack/lit-query @tanstack/query-core lit
24```
25β
26or
27β
28```bash
29bun add @tanstack/lit-query @tanstack/query-core lit
30```
31β
32`@tanstack/query-core` is a peer dependency of `@tanstack/lit-query`. Even though the Lit docs import user-facing APIs from `@tanstack/lit-query`, your app should install `@tanstack/query-core` explicitly.
33β
34## Requirements
35β
36Lit Query is intended for Lit 2.8 and newer, including Lit 3. It uses Lit reactive controllers and Lit context, so query consumers should be `ReactiveControllerHost` instances such as `LitElement`.
37β
38TanStack Query is optimized for modern browsers:
39β
40```txt
41Chrome >= 91
42Firefox >= 90
43Edge >= 91
44Safari >= 15
45iOS >= 15
46Opera >= 77
47```
48β
49## Provider Setup
50β
51Create a `QueryClient`, provide it with `QueryClientProvider`, and register your custom element. The package exports the provider class but does not call `customElements.define` for you.
52β
53### Subclass Pattern
54β
55```ts
56import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
57β
58const queryClient = new QueryClient()
59β
60class AppQueryProvider extends QueryClientProvider {
61 constructor() {
62 super()
63 this.client = queryClient
64 }
65}
66β
67customElements.define('app-query-provider', AppQueryProvider)
68```
69β
70```html
71<app-query-provider>
72 <todos-view></todos-view>
73</app-query-provider>
74```
75β
76### Direct Provider Element
77β
78You can register the provider class directly and bind its `client` property from a Lit template. The dot is important: `.client=${queryClient}` is a property binding, not an HTML attribute.
79β
80```ts
81import { LitElement, html } from 'lit'
82import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
83β
84const queryClient = new QueryClient()
85β
86customElements.define('query-client-provider', QueryClientProvider)
87β
88class AppRoot extends LitElement {
89 render() {
90 return html`
91 <query-client-provider .client=${queryClient}>
92 <todos-view></todos-view>
93 </query-client-provider>
94 `
95 }
96}
97```
98β
99If a connected provider has no `client`, it throws. See the generated [`QueryClientProvider` reference](./reference/classes/QueryClientProvider.md) for the full contract.
100β
101## Render Roots
102β
103The snippets in these docs use Lit's default shadow DOM. Lit Query controllers and `QueryClientProvider` work with shadow DOM and light DOM because they use the host lifecycle and Lit context, not global selectors.
104β
105Some runnable examples override `createRenderRoot()` and return `this` so their demo markup stays in light DOM for shared page styles and test selectors. That override is not required for Lit Query. Use light DOM only when your app has a separate reason to expose a component's internal markup to global CSS, tests, or non-shadow-DOM integration code.
106β
107## Devtools Status
108β
109Lit Devtools are not available yet. This is a current adapter limitation, not an installation step.