Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

index.js

43 lines1.2 KB

1/* eslint-disable jsx-a11y/anchor-is-valid */
2import React from "react";
3import ReactDOM from "react-dom/client";
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 );
17​
18function Example() {
19 const { isLoading, error, data, isFetching } = useQuery(["repoData"], () =>
20 axios
21 .get("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 );
41​
42const rootElement = document.getElementById("root");
43ReactDOM.createRoot(rootElement).render(<App />);