Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

QueryClientProvider.md

96 lines2.3 KB

1---
2id: QueryClientProvider
3title: QueryClientProvider
4---
5​
6Defined in: [packages/lit-query/src/QueryClientProvider.ts:62](https://github.com/TanStack/query/blob/main/packages/lit-query/src/QueryClientProvider.ts#L62)
7​
8Lit element that provides a `QueryClient` to descendant Lit Query
9controllers through Lit context.
10​
11The `client` is a property, not an attribute. When rendering this element in
12a Lit template, bind it with property binding: `.client=${queryClient}`.
13The provider throws if it connects without a client, or if an already
14connected provider has its client cleared.
15​
16This class is not registered as a custom element by the package. Applications
17must register either a subclass or the class itself with
18`customElements.define`.
19​
20## Examples
21​
22```ts
23import { html, LitElement } from 'lit'
24import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
25​
26const queryClient = new QueryClient()
27​
28class AppQueryProvider extends QueryClientProvider {
29 constructor() {
30 super()
31 this.client = queryClient
32 }
34​
35customElements.define('app-query-provider', AppQueryProvider)
36​
37class AppRoot extends LitElement {
38 render() {
39 return html`<app-query-provider><todos-view></todos-view></app-query-provider>`
40 }
42```
43​
44```ts
45import { html } from 'lit'
46import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
47​
48const queryClient = new QueryClient()
49​
50customElements.define('query-client-provider', QueryClientProvider)
51​
52const view = html`
53 <query-client-provider .client=${queryClient}>
54 <todos-view></todos-view>
55 </query-client-provider>
57```
58​
59## Extends
60​
61- `LitElement`
62​
63## Constructors
64​
65### Constructor
66​
67```ts
68new QueryClientProvider(): QueryClientProvider;
69```
70​
71Defined in: [packages/lit-query/src/QueryClientProvider.ts:80](https://github.com/TanStack/query/blob/main/packages/lit-query/src/QueryClientProvider.ts#L80)
72​
73#### Returns
74​
75`QueryClientProvider`
76​
77#### Overrides
78​
79```ts
80LitElement.constructor
81```
82​
83## Properties
84​
85### client
86​
87```ts
88client: QueryClient;
89```
90​
91Defined in: [packages/lit-query/src/QueryClientProvider.ts:74](https://github.com/TanStack/query/blob/main/packages/lit-query/src/QueryClientProvider.ts#L74)
92​
93The `QueryClient` provided to descendant controllers and global fallback
94helpers while this provider is connected.
95​
96Bind this as a property in Lit templates with `.client=${queryClient}`.