()
| 20 | } |
| 21 | |
| 22 | function Example() { |
| 23 | const state = useQuery(() => ({ |
| 24 | queryKey: ['repoData'], |
| 25 | queryFn: async () => { |
| 26 | const response = await fetch( |
| 27 | 'https://api.github.com/repos/TanStack/query', |
| 28 | ) |
| 29 | return await response.json() |
| 30 | }, |
| 31 | })) |
| 32 | |
| 33 | return ( |
| 34 | <Switch> |
| 35 | <Match when={state.isPending}>Loading...</Match> |
| 36 | <Match when={state.error}> |
| 37 | {'An error has occurred: ' + (state.error as Error).message} |
| 38 | </Match> |
| 39 | <Match when={state.data !== undefined}> |
| 40 | <div> |
| 41 | <h1>{state.data.name}</h1> |
| 42 | <p>{state.data.description}</p> |
| 43 | <strong>👀 {state.data.subscribers_count}</strong>{' '} |
| 44 | <strong>✨ {state.data.stargazers_count}</strong>{' '} |
| 45 | <strong>🍴 {state.data.forks_count}</strong> |
| 46 | <div>{state.isFetching ? 'Updating...' : ''}</div> |
| 47 | </div> |
| 48 | </Match> |
| 49 | </Switch> |
| 50 | ) |
| 51 | } |
| 52 | render(() => <App />, document.getElementById('root') as HTMLElement) |
nothing calls this directly
no test coverage detected
searching dependent graphs…