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

Function Example

examples/react/devtools-panel/src/index.tsx:26–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected