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

Function Example

examples/react/simple/src/index.tsx:20–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected