MCPcopy Create free account
hub / github.com/TanStack/query / BasicQueryExample

Class BasicQueryExample

examples/lit/basic/src/basic-query.ts:31–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29customElements.define('basic-query-provider', BasicQueryProvider)
30
31class BasicQueryExample extends LitElement {
32 private readonly todos = createQueryController<TodosResponse, Error>(this, {
33 queryKey: ['todos'],
34 queryFn: fetchTodosFromServer,
35 })
36
37 protected override createRenderRoot(): HTMLElement | DocumentFragment {
38 return this
39 }
40
41 render() {
42 const query = this.todos()
43 return html`
44 <main>
45 <h1>Basic Query Example</h1>
46 <p data-testid="basic-query-status">
47 Status: <strong>${query.status}</strong>
48 </p>
49 <button
50 data-testid="basic-refetch"
51 @click=${() => this.todos.refetch()}
52 >
53 Refetch
54 </button>
55
56 ${query.isPending
57 ? html`<p data-testid="basic-loading">Loading...</p>`
58 : null}
59 ${query.isError
60 ? html`<p data-testid="basic-error">Error: ${String(query.error)}</p>`
61 : null}
62
63 <ul data-testid="basic-todo-list">
64 ${(query.data?.items ?? []).map(
65 (todo) =>
66 html`<li data-testid="basic-todo-item">${todo.title}</li>`,
67 )}
68 </ul>
69 </main>
70 `
71 }
72}
73
74customElements.define('basic-query-example', BasicQueryExample)
75

Callers

nothing calls this directly

Calls 1

createQueryControllerFunction · 0.90

Tested by

no test coverage detected