Skip to content

Latest commit

 

History

History
88 lines (65 loc) · 2.05 KB

README.md

File metadata and controls

88 lines (65 loc) · 2.05 KB

COVID-19 Data Tracker

A React app to show the data of Covid-19 by each country/region.

screenshot-01

screenshot-02

notes

API:

components/modules

  • chart.js
  • react-chartjs-2
  • leaflet
  • react-leaflet
  • axios
  • react-countup

NOTE: Need to give .leaflet-container a height & a width, otherwise it won't show up. And also need to add the default style of leaflet - import "leaflet/dist/leaflet.css";.

materials


I used this API https://covid19.mathdro.id/api at the beginning which made creating the 'Cases by Country/Region' list quite inconvenient, but because of this I learned a lot of Promise. Here's the code:

import axios from "axios";

const url = "https://covid19.mathdro.id/api";

// Fetch data by region
const FetchByRegion = async (name) => {
  try {
    const {
      data: { confirmed, recovered, deaths },
    } = await axios.get(`${url}/countries/${name}`);
    return {
      name,
      confirmed,
      recovered,
      deaths,
    };
  } catch (error) {
    console.log("error", error.message);
  }
};

// Fetch data for regions
const fetchRegionData = async () => {
  try {
    const {
      data: { countries },
    } = await axios.get(`${url}/countries`);

    const regionNames = countries
      .filter((country) => country.name !== "Gambia")
      .map((country) => country.name);

    // let regionDatas = [];

    const regionDatas = regionNames.map(async (name) => {
      return await FetchByRegion(name);
    });

    return Promise.all(regionDatas);
  } catch (error) {
    console.log("error", error.message);
  }
};

export { fetchRegionData };