Open History to see the last commit
1/* eslint-disable jsx-a11y/anchor-is-valid */
2import React from "react";
3import ReactDOM from "react-dom";
4import { QueryClient, QueryClientProvider, useQuery } from "react-query";
5import { ReactQueryDevtools } from "react-query/devtools";
6import axios from "axios";
7β
8const queryClient = new QueryClient();
9β
10export default function App() {
11 return (
12 <QueryClientProvider client={queryClient}>
13 <Example />
14 </QueryClientProvider>
15 );
16}
17β
18function Example() {
19 const { isLoading, error, data, isFetching } = useQuery("repoData", () =>
20 axios.get(
21 "https://api.github.com/repos/tannerlinsley/react-query"
22 ).then((res) => res.data)
23 );
24β
25 if (isLoading) return "Loading...";
26β
27 if (error) return "An error has occurred: " + error.message;
28β
29 return (
30 <div>
31 <h1>{data.name}</h1>
32 <p>{data.description}</p>
33 <strong>π {data.subscribers_count}</strong>{" "}
34 <strong>β¨ {data.stargazers_count}</strong>{" "}
35 <strong>π΄ {data.forks_count}</strong>
36 <div>{isFetching ? "Updating..." : ""}</div>
37 <ReactQueryDevtools initialIsOpen />
38 </div>
39 );
40}
41β
42const rootElement = document.getElementById("root");
43ReactDOM.render(<App />, rootElement);