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

index.js

42 lines1.2 KB

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 );
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 );
40​
41const rootElement = document.getElementById("root");
42ReactDOM.render(<App />, rootElement);