-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathApp.jsx
More file actions
47 lines (39 loc) · 1.06 KB
/
App.jsx
File metadata and controls
47 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
QueryClient,
QueryClientProvider,
useQuery,
} from "@tanstack/react-query";
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import axios from "axios";
import './App.css'
const queryClient = new QueryClient();
function CurrentTime(props) {
const { isLoading, error, data, isFetching } = useQuery({
queryKey: [props.api],
queryFn: () =>
axios
.get(`${props.api}`)
.then((res) => res.data),
});
if (isLoading) return `Loading ${props.api}... `;
if (error) return "An error has occurred: " + error.message;
return (
<div className="App">
<p>---</p>
<p>API: {data.api}</p>
<p>Time from DB: {data.now}</p>
<div>{isFetching ? "Updating..." : ""}</div>
</div>
)
}
export function App() {
return (
<QueryClientProvider client={queryClient}>
<h1>Hey Team from shipyard! 🚢</h1>
<CurrentTime api="/api/golang/"/>
<CurrentTime api="/api/node/"/>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
);
}
export default App