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

Class CharacterList

examples/lit/batching/src/character-list.ts:5–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import { charactersQueries } from './services/characters/queries'
4
5class CharacterList extends LitElement {
6 static properties = {
7 ids: { attribute: false },
8 }
9
10 ids: Array<number> = []
11
12 private readonly characters = createQueriesController(this, () => ({
13 queries: this.ids.map((id) => charactersQueries.detail(id)),
14 }))
15
16 protected override createRenderRoot(): HTMLElement | DocumentFragment {
17 return this
18 }
19
20 render() {
21 return this.characters().map((character) => {
22 if (character.status === 'pending') {
23 return 'Loading...'
24 }
25 if (character.status === 'error') {
26 return 'Error...'
27 }
28 if (character.data === null) {
29 return 'Not found ...'
30 }
31
32 return html`
33 <div style="display: flex">
34 <img
35 width="100"
36 height="100"
37 alt=${character.data.image}
38 src=${character.data.image}
39 />
40 <div style="padding-left: 10px; text-align: left">
41 <h5 style="margin-top: 0; margin-bottom: 5px">
42 ${character.data.name} (#${character.data.id})
43 </h5>
44 <p style="margin-top: 0; margin-bottom: 2px">
45 Status: ${character.data.status}
46 </p>
47 <p style="margin-top: 0; margin-bottom: 2px">
48 Species: ${character.data.species}
49 </p>
50 <p style="margin-top: 0; margin-bottom: 2px">
51 Gender: ${character.data.gender}
52 </p>
53 </div>
54 </div>
55 `
56 })
57 }
58}
59
60customElements.define('character-list', CharacterList)

Callers

nothing calls this directly

Calls 1

createQueriesControllerFunction · 0.90

Tested by

no test coverage detected