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

Function Example

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

Source from the content-addressed store, hash-verified

19}
20
21function Example() {
22 const { isPending, error, data, isFetching } = useQuery({
23 queryKey: ['repoData'],
24 queryFn: async () => {
25 const response = await fetch(
26 'https://api.github.com/repos/TanStack/query',
27 )
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