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