Open History to see the last commit
1import { useQuery } from '@tanstack/react-query'
2β
3type DogsResp = {
4 message: {
5 [dog: string]: string[]
6 }
7}
8β
9export const DogList = () => {
10 const { data, status } = useQuery<DogsResp>({
11 queryKey: ['dogs'],
12 queryFn: async () => {
13 const resp = await fetch('https://dog.ceo/api/breeds/list/all')
14 if (resp.ok) {
15 return resp.json()
16 }
17 throw new Error('something went wrong')
18 },
19 })
20β
21 if (status === 'pending') return 'Loading...'
22β
23 if (status === 'error') return 'Error!'
24β
25 const dogs = Object.keys(data?.message)
26β
27 return (
28 <div>
29 {dogs.map((dog) => (
30 <div key={dog}>{dog}</div>
31 ))}
32 </div>
33 )
34}