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