Created
June 5, 2020 16:00
-
-
Save beardedtim/1e72d11df133fe2a6c471a0a69e1a678 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState, useEffect} from 'react'; | |
import Axios from 'axios'; | |
import './App.css'; | |
import AutoComplete from './AutoComplete' | |
function App() { | |
const [globalStats, setGlobalStats] = useState({}) | |
const [countryStats, setCountryStats] = useState({}) | |
const retriveStats = () => Axios.get('https://api.covid19api.com/summary') | |
.then(res => { | |
setGlobalStats(res.data.Global) | |
setCountryStats(res.data.Countries) | |
}) | |
useEffect(retriveStats, []) | |
return ( | |
<div className="App"> | |
<header>Covid19 Stats</header> | |
{Object.entries(globalStats) | |
.map(([key, value ], i) => ( | |
{/* cannot have more than one value that has ID global | |
so changing to classname | |
*/} | |
<div className='global' key={i}> | |
<div id="key">{key}: </div> | |
<div>{formatVal(value)}</div> | |
</div> | |
)) | |
} | |
<div className='App-Component'> | |
<AutoComplete countryNames={countryStats && countryStats.map(c => c.Country)}/> | |
</div> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment