MCPcopy Create free account
hub / github.com/TanStack/query / Example

Function Example

examples/solid/simple/src/index.tsx:22–52  ·  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 if (!response.ok) throw new Error('Failed to fetch repo data')
30 return await response.json()
31 },
32 }))
33
34 return (
35 <Switch>
36 <Match when={state.isPending}>Loading...</Match>
37 <Match when={state.error}>
38 {'An error has occurred: ' + (state.error as Error).message}
39 </Match>
40 <Match when={state.data !== undefined}>
41 <div>
42 <h1>{state.data.name}</h1>
43 <p>{state.data.description}</p>
44 <strong>👀 {state.data.subscribers_count}</strong>{' '}
45 <strong>✨ {state.data.stargazers_count}</strong>{' '}
46 <strong>🍴 {state.data.forks_count}</strong>
47 <div>{state.isFetching ? 'Updating...' : ''}</div>
48 </div>
49 </Match>
50 </Switch>
51 )
52}
53const root = document.getElementById('root')
54if (!root) throw new Error('Missing #root element')
55

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected