()
| 19 | } |
| 20 | |
| 21 | function Example() { |
| 22 | const { isPending, error, data, isFetching } = useQuery({ |
| 23 | queryKey: ['repoData'], |
| 24 | queryFn: async () => { |
| 25 | const response = await fetch( |
| 26 | 'https://api.github.com/repos/TanStack/query', |
| 27 | ) |
| 28 | return await response.json() |
| 29 | }, |
| 30 | }) |
| 31 | |
| 32 | if (isPending) return 'Loading...' |
| 33 | |
| 34 | if (error) return 'An error has occurred: ' + error.message |
| 35 | |
| 36 | return ( |
| 37 | <div> |
| 38 | <h1>{data.full_name}</h1> |
| 39 | <p>{data.description}</p> |
| 40 | <strong>👀 {data.subscribers_count}</strong>{' '} |
| 41 | <strong>✨ {data.stargazers_count}</strong>{' '} |
| 42 | <strong>🍴 {data.forks_count}</strong> |
| 43 | <div>{isFetching ? 'Updating...' : ''}</div> |
| 44 | </div> |
| 45 | ) |
| 46 | } |
| 47 | |
| 48 | const rootElement = document.getElementById('root') |
| 49 | if (!rootElement) throw new Error('Missing #root element') |
nothing calls this directly
no test coverage detected