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

Characters.tsx

40 lines1.1 KB

1import { For, Match, Switch } from 'solid-js'
2import { A } from '@solidjs/router'
3import { useQuery } from '@tanstack/solid-query'
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 <article>
24 <A
25 class="text-blue-500 hover:underline"
26 href={`/characters/${person.id}`}
27 >
28 <h6 class="text-xl">
29 {person.name} - {person.gender}: {person.species}
30 </h6>
31 </A>
32 </article>
33 )}
34 </For>
35 </div>
36 )}
37 </Match>
38 </Switch>
39 )