Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions 05-example-web-application/client-react/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,43 @@ import {
QueryClient,
QueryClientProvider,
useQuery,
} from "@tanstack/react-query";
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import axios from "axios";
} from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import axios from 'axios';

import './App.css'
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),
queryFn: () => axios.get(`${props.api}`).then((res) => res.data),
});

if (isLoading) return `Loading ${props.api}... `;

if (error) return "An error has occurred: " + error.message;
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>{isFetching ? 'Updating...' : ''}</div>
</div>
)
);
}

export function App() {
return (
<QueryClientProvider client={queryClient}>
<h1>Hey Team! 👋</h1>
<CurrentTime api="/api/golang/"/>
<CurrentTime api="/api/node/"/>
<h1>Hey Team from Shipyard! 🚢</h1>
<CurrentTime api="/api/golang/" />
<CurrentTime api="/api/node/" />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
);
}

export default App
export default App;