Skip to content

Instantly share code, notes, and snippets.

@EricCote
Created February 16, 2022 16:52
Show Gist options
  • Save EricCote/69d0cde6fb8ea7d88cc2bba119646ddd to your computer and use it in GitHub Desktop.
Save EricCote/69d0cde6fb8ea7d88cc2bba119646ddd to your computer and use it in GitHub Desktop.
Projet qui affiche la covid
import React, { useEffect, useState } from "react";
import TableCovid from "./TableCovid";
function Covid() {
const [liste, setListe] = useState([]);
useEffect(() => {
getData();
}, []);
async function getData() {
const resp = await fetch(
"https://disease.sh/v3/covid-19/countries?sort=cases"
);
const data = await resp.json();
setListe(data);
}
return (
<>
<h1>Covid</h1>
<TableCovid liste={liste} />
</>
);
}
export default Covid;
import React from "react";
import { Table } from "react-bootstrap";
function TableCovid({ liste }) {
return (
<Table>
<thead>
<tr>
<th>Pays</th>
<th>Cas total</th>
<th>Morts</th>
</tr>
</thead>
<tbody>
{liste.map((item) => (
<tr key={item.country}>
<td>{item.country}</td>
<td>{item.cases}</td>
<td>{item.deaths}</td>
</tr>
))}
</tbody>
</Table>
);
}
export default TableCovid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment