aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2020-11-13 20:43:44 -0500
committerGalen Guyer <galen@galenguyer.com>2020-11-13 20:43:44 -0500
commit26f0066f9b2daa904d4fe4cac80841cbe40360ca (patch)
tree691f0d4b62c73ab4f486bea8ee4bdc564b1343c4
parent5d5c39b6d318a91dd5062d829cecf3dcdd25ccab (diff)
get data from api
-rw-r--r--src/App.js31
-rw-r--r--src/index.js1
2 files changed, 23 insertions, 9 deletions
diff --git a/src/App.js b/src/App.js
index ee4fbc4..0600437 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,18 +1,31 @@
+import useSWR from "swr";
import logo from "./logo.svg";
import "./App.css";
+const url = "https://rcpoller.galenguyer.com/api/v0/history";
+
function App() {
+ const { data: data, error: error } = useSWR(url);
+
+ if (error)
+ return (
+ <div className="App">
+ <h1>RIT Covid Dashboard</h1>
+ <h2>An error occurred</h2>
+ </div>
+ );
+ if (!data)
+ return (
+ <div className="App">
+ <h1>RIT Covid Dashboard</h1>
+ <h2>Loading latest data...</h2>
+ </div>
+ );
+
return (
<div className="App">
- <header className="App-header">
- <img src={logo} className="App-logo" alt="logo" />
- <p>
- Edit <code>src/App.js</code> and save to reload.
- </p>
- <a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
- Learn React
- </a>
- </header>
+ <h1>RIT Covid Dashboard</h1>
+ <h2>Data Loaded</h2>
</div>
);
}
diff --git a/src/index.js b/src/index.js
index ea743ca..4c1dc74 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,6 +3,7 @@ import ReactDOM from "react-dom";
import { SWRConfig } from "swr";
import "./index.css";
import App from "./App";
+import reportWebVitals from "./reportWebVitals";
const fetcher = (...args) => fetch(...args).then((res) => res.json());