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

Characters.tsx

29 lines880 Bytes

1import { useQuery } from '@tanstack/preact-query'
2import { charactersQueries } from './services/characters/queries'
3​
4export default function Characters() {
5 const { status, data } = useQuery(charactersQueries.list())
6​
7 if (status === 'pending') return <p>Loading...</p>
8 if (status === 'error') return <p>Error :(</p>
9​
10 return (
11 <div>
12 <h2 className="text-4xl">Characters</h2>
13 {data.results.map((person) => {
14 const personUrlParts = person.url.split('/').filter(Boolean)
15 const personId = personUrlParts[personUrlParts.length - 1]
16 return (
17 <article key={personId}>
18 <a
19 className="text-blue-500 hover:underline"
20 href={`/characters/${personId}`}
21 >
22 <h6 className="text-xl">{person.name}</h6>
23 </a>
24 </article>
25 )
26 })}
27 </div>
28 )