Skip to content

Instantly share code, notes, and snippets.

@rockiger
Created February 19, 2021 08:41
Show Gist options
  • Save rockiger/5d4293f837b8948e34bdde0e09b7988e to your computer and use it in GitHub Desktop.
Save rockiger/5d4293f837b8948e34bdde0e09b7988e to your computer and use it in GitHub Desktop.
// 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