Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
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>
  )
}

...