...
Code Block | ||
---|---|---|
| ||
function Example() { const { isLoading, isFetching, isInitialLoading, error, data } = useQuery({ queryKey: ['repoData'], queryFn: () => // Example API call with `fetch` return fetch('https://api.github.com/repos/tannerlinsley/react-query').then( (res) => res.json(), ), // Example API call with `getAuthenticatedHttpClient` return getAuthenticatedHttpClient().get(...); }) if (isLoading) { return 'Loading...' } if (error) { return 'An error has occurred: ' + error.message } return ( <div> <h1>{data.name}</h1> <p>{data.description}</p> <strong>👀 {data.subscribers_count}</strong>{' '} <strong>✨ {data.stargazers_count}</strong>{' '} <strong>🍴 {data.forks_count}</strong> </div> ) } |
...