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

Characters.tsx

42 lines1.2 KB

1import { A } from '@solidjs/router'
2import { useQuery } from '@tanstack/solid-query'
3import { For, Match, Switch } from 'solid-js'
4import { charactersQueries } from './services/characters/queries'
5​
6export default function Characters() {
7 const query = useQuery(() => charactersQueries.list())
8​
9 return (
10 <Switch>
11 <Match when={query.status === 'pending'}>
12 <p>Loading...</p>
13 </Match>
14 <Match when={query.status === 'error'}>
15 <p>Error :(</p>
16 </Match>
17 <Match when={query.data}>
18 {(data) => (
19 <div>
20 <h2 class="text-4xl">Characters</h2>
21 <For each={data().results}>
22 {(person) => {
23 const personUrlParts = person.url.split('/').filter(Boolean)
24 const personId = personUrlParts[personUrlParts.length - 1]
25 return (
26 <article>
27 <A
28 class="text-blue-500 hover:underline"
29 href={`/characters/${personId}`}
30 >
31 <h6 class="text-xl">{person.name}</h6>
32 </A>
33 </article>
34 )
35 }}
36 </For>
37 </div>
38 )}
39 </Match>
40 </Switch>
41 )