-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
61 lines (57 loc) · 1.81 KB
/
App.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useEffect, useState } from "react";
import CurrencyTableRoute from "./routes/CurrencyTableRoute";
import ErrorRoute from "./routes/ErrorRoute";
import ConverterRoute from "./routes/ConverterRoute";
import AppBar from "@material-ui/core/AppBar";
import Toolbar from "@material-ui/core/Toolbar";
import { Redirect } from "react-router";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
function App() {
const [currencies, setCurrencies] = useState(null);
const [fetchError, setFetchError] = useState(false);
useEffect(() => {
// fetch("http://localhost:3001/currencies")
fetch("http://localhost:5000/today/list")
.then((res) => res.json())
.then((data) => setCurrencies(data))
.catch(() => setFetchError(true));
}, []);
return (
<div className="App">
<Router>
<AppBar position="static" color="transparent">
<Toolbar>
<Link
to="/table"
style={{ textDecoration: "none", color: "inherit" }}
>
Table
</Link>
<Link
to="/converter"
style={{
textDecoration: "none",
marginLeft: 10,
color: "inherit",
}}
>
Converter
</Link>
</Toolbar>
</AppBar>
<Switch>
<Route path="/table">
{fetchError && <ErrorRoute />}
{currencies && <CurrencyTableRoute currencies={currencies} />}
</Route>
<Route path="/converter">
{fetchError && <ErrorRoute />}
{currencies && <ConverterRoute currencies={currencies} />}
</Route>
<Redirect from="/" to="/converter" />
</Switch>
</Router>
</div>
);
}
export default App;