Open History to see the last commit
1import { LitElement, html } from 'lit'
2import {
3 QueryClient,
4 QueryClientProvider,
5 createQueryController,
6} from '@tanstack/lit-query'
7import { reposQueries } from './services/repos/queries'
8β
9const queryClient = new QueryClient()
10β
11class SimpleQueryProvider extends QueryClientProvider {
12 constructor() {
13 super()
14 this.client = queryClient
15 }
16}
17β
18class SimpleExample extends LitElement {
19 private readonly repo = createQueryController(this, reposQueries.detail())
20β
21 protected override createRenderRoot(): HTMLElement | DocumentFragment {
22 return this
23 }
24β
25 render() {
26 const { data, error, isFetching, isPending } = this.repo()
27β
28 if (isPending) return html`Loading...`
29β
30 if (error) return html`An error has occurred: ${error.message}`
31β
32 return html`
33 <h1>${data.name}</h1>
34 <p>${data.description}</p>
35 <strong>π ${data.subscribers_count}</strong>
36 <strong>β¨ ${data.stargazers_count}</strong>
37 <strong>π΄ ${data.forks_count}</strong>
38 <div>${isFetching ? 'Updating...' : ''}</div>
39 `
40 }
41}
42β
43class SimpleApp extends LitElement {
44 protected override createRenderRoot(): HTMLElement | DocumentFragment {
45 return this
46 }
47β
48 render() {
49 return html`
50 <simple-query-provider>
51 <simple-example></simple-example>
52 </simple-query-provider>
53 `
54 }
55}
56β
57customElements.define('simple-query-provider', SimpleQueryProvider)
58customElements.define('simple-example', SimpleExample)
59customElements.define('simple-app', SimpleApp)