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

main.ts

40 lines1.0 KB

1import { LitElement, html } from 'lit'
2import { Router } from '@lit-labs/router'
3import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
4import './character-view'
5import './home-view'
6​
7const queryClient = new QueryClient()
8​
9class PrefetchingQueryProvider extends QueryClientProvider {
10 constructor() {
11 super()
12 this.client = queryClient
13 }
15​
16class PrefetchingApp extends LitElement {
17 private readonly router = new Router(this, [
18 { path: '/', render: () => html`<home-view></home-view>` },
19 {
20 path: '/character/:id',
21 render: ({ id }) =>
22 html`<character-view .characterId=${id}></character-view>`,
23 },
24 ])
25​
26 protected override createRenderRoot(): HTMLElement | DocumentFragment {
27 return this
28 }
29​
30 render() {
31 return html`
32 <prefetching-query-provider
33 >${this.router.outlet()}</prefetching-query-provider
34 >
35 `
36 }
38​
39customElements.define('prefetching-query-provider', PrefetchingQueryProvider)
40customElements.define('prefetching-app', PrefetchingApp)