Created
February 16, 2022 16:52
-
-
Save EricCote/69d0cde6fb8ea7d88cc2bba119646ddd to your computer and use it in GitHub Desktop.
Projet qui affiche la covid
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, { 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; |
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 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