Created
February 19, 2021 08:41
-
-
Save rockiger/5d4293f837b8948e34bdde0e09b7988e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// App.js | |
import { QueryClient, QueryClientProvider} from 'react-query' | |
const queryClient = new QueryClient() | |
export default function App() { | |
return ( | |
<QueryClientProvider client={queryClient}> | |
<Component /> | |
</QueryClientProvider> | |
) | |
} | |
// Component.js | |
import { useQuery } from 'react-query' | |
function Component() { | |
const { isLoading, error, data } = useQuery('issues', () => | |
fetch('https://api.github.com/repos/rockiger/metado').then(res => | |
res.json() | |
) | |
) | |
if (isLoading) return 'Loading...' | |
if (error) return 'An error has occurred: ' + error.message | |
return ( | |
<> | |
<h1>{data.name}</h1> | |
<p>{data.description}</p> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment