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

main.ts

49 lines1.3 KB

1import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
2import { LitElement, html } from 'lit'
3import { worker } from './mocks'
4import './approach-tabs'
5​
6const queryClient = new QueryClient({
7 defaultOptions: {
8 queries: {
9 staleTime: 60 * 1000,
10 },
11 },
12})
13​
14class OptimisticUpdatesQueryProvider extends QueryClientProvider {
15 constructor() {
16 super()
17 this.client = queryClient
18 }
20​
21class OptimisticUpdatesApp extends LitElement {
22 protected override createRenderRoot(): HTMLElement | DocumentFragment {
23 return this
24 }
25​
26 render() {
27 return html`
28 <optimistic-updates-query-provider>
29 <main style="max-width: 600px; margin: 0 auto; padding: 2rem 1rem">
30 <h1>Optimistic Updates with TanStack Query</h1>
31 <p style="color: #666; margin-bottom: 1.5rem">
32 Add todos to see optimistic updates in action. The server randomly
33 fails ~30% of the time so you can observe automatic rollback.
34 </p>
35 <approach-tabs></approach-tabs>
36 </main>
37 </optimistic-updates-query-provider>
38 `
39 }
41​
42customElements.define(
43 'optimistic-updates-query-provider',
44 OptimisticUpdatesQueryProvider,
46​
47worker.start({ onUnhandledRequest: 'bypass' }).then(() => {
48 customElements.define('optimistic-updates-app', OptimisticUpdatesApp)
49})