Open History to see the last commit
1import { Link as RouterLink } from 'react-router-dom'
2import { useQuery } from '@tanstack/react-query'
3import { getCharacters } from './api'
4β
5export default function Characters() {
6 const { status, data } = useQuery({
7 queryKey: ['characters'],
8 queryFn: () => getCharacters(),
9 })
10β
11 if (status === 'pending') return <p>Loading...</p>
12 if (status === 'error') return <p>Error :(</p>
13β
14 return (
15 <div>
16 <h2 className="text-4xl">Characters</h2>
17 {data.results.map((person: any) => {
18 const personUrlParts = person.url.split('/').filter(Boolean)
19 const personId = personUrlParts[personUrlParts.length - 1]
20 return (
21 <article key={personId}>
22 <RouterLink
23 className="text-blue-500 hover:underline"
24 to={`/characters/${personId}`}
25 >
26 <h6 className="text-xl">{person.name}</h6>
27 </RouterLink>
28 </article>
29 )
30 })}
31 </div>
32 )
33}