From 26f0066f9b2daa904d4fe4cac80841cbe40360ca Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Fri, 13 Nov 2020 20:43:44 -0500 Subject: get data from api --- src/App.js | 31 ++++++++++++++++++++++--------- src/index.js | 1 + 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src') 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 ( +
+

RIT Covid Dashboard

+

An error occurred

+
+ ); + if (!data) + return ( +
+

RIT Covid Dashboard

+

Loading latest data...

+
+ ); + return (
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+

RIT Covid Dashboard

+

Data Loaded

); } 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()); -- cgit v1.2.3