MCPcopy Index your code
hub / github.com/TanStack/query / Example

Function Example

examples/solid/simple/src/index.tsx:22–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22function 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}
52render(() => <App />, document.getElementById('root') as HTMLElement)

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…