Created
May 1, 2021 07:25
-
-
Save NaveenDA/03c860c1915aa26c490f0edfb1c8ccef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { QueryClient, QueryClientProvider, useQuery } from 'react-query' | |
const queryClient = new QueryClient() | |
export default function App() { | |
return ( | |
<QueryClientProvider client={queryClient}> | |
<Example /> | |
</QueryClientProvider> | |
) | |
} | |
function Example() { | |
const { isLoading, error, data } = useQuery('repoData', () => | |
fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res => | |
res.json() | |
) | |
) | |
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> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment