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";
6β
7const queryClient = new QueryClient();
8β
9export default function App() {
10 return (
11 <QueryClientProvider client={queryClient}>
12 <Example />
13 </QueryClientProvider>
14 );
15}
16β
17function Example() {
18 const { isLoading, error, data, isFetching } = useQuery("repoData", () =>
19 fetch(
20 "https://api.github.com/repos/tannerlinsley/react-query"
21 ).then((res) => res.json())
22 );
23β
24 if (isLoading) return "Loading...";
25β
26 if (error) return "An error has occurred: " + error.message;
27β
28 return (
29 <div>
30 <h1>{data.name}</h1>
31 <p>{data.description}</p>
32 <strong>π {data.subscribers_count}</strong>{" "}
33 <strong>β¨ {data.stargazers_count}</strong>{" "}
34 <strong>π΄ {data.forks_count}</strong>
35 <div>{isFetching ? "Updating..." : ""}</div>
36 <ReactQueryDevtools initialIsOpen />
37 </div>
38 );
39}
40β
41const rootElement = document.getElementById("root");
42ReactDOM.render(<App />, rootElement);