doc: create getCountriesData with app__header class

This commit is contained in:
Leon Xu committed 2022-05-02 19:15:38 -07:00
1 parent d788812a8a
commit f6c75d0f74
1 file changed
+38 -3
+38 -3
View File
@@ -1,9 +1,44 @@
import React from 'react';
import './App.css';
import React, { useEffect, useState } from "react";
import { FormControl, Select, MenuItem } from "@material-ui/core";
import "./App.css";
function App() {
const [countries, setCountries] = useState([]);
const [country, setCountry] = useState("worldwide");
useEffect(() => {
const getCountriesData = async () => {
await fetch("https://disease.sh/v3/covid-19/countries")
.then((response) => response.json())
.then((data) => {
const countries = data.map((country) => ({
name: country.country,
value: country.countryInfo.iso2,
}));
setCountries(countries);
});
};
getCountriesData();
}, [countries]);
const countryChange = (e) => {
const countryCode = e.target.value;
setCountry(countryCode);
};
return (
<section className='app'></section>
<section className="app">
<header className="app__header">
<h1>COVID-19 Tracker</h1>
<FormControl className="app__dropdown">
<Select variant="outlined" onChange={countryChange} value={country}>
<MenuItem value="worldwide">Worldwide</MenuItem>
{countries.map((country) => (
<MenuItem value={country.value}>{country.name}</MenuItem>
))}
</Select>
</FormControl>
</header>
</section>
);
}