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