adrianhajdin / project_corona_tracker

This is a code repository for the corresponding YouTube video. In this tutorial, we are going to build and deploy a corona tracker application. Covered topics: React.js, Chart.js, Material UI, and much more.
https://covid19statswebsite.netlify.com/
1.46k stars 481 forks source link

unhandled Rejection (TypeError): Cannot read property 'length' of undefined #23

Open MERCERNYC opened 4 years ago

MERCERNYC commented 4 years ago

After working on fetchDailyData I am getting this error.

Screen Shot 2020-10-08 at 8 59 27 AM

React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. in Chart (at App.js:24) in div (at App.js:22) in App (at src/index.js:6)

shaikhreza43 commented 4 years ago

Bro. I have the same issue. This is because the api/daily is not working and it's not returning any response. So you are getting that length error. You can check in the network tab of the developer console. There is nothing wrong in our code

shaikhreza43 commented 4 years ago

Bro, Use this in your Api.js

export const fetchDailyData = async () => { try { const { data } = await axios.get(https://api.covidtracking.com/v1/us/daily.json); const modifiedData = data.map((dailydata) => ({ confirmed: dailydata.positive, deaths: dailydata.death, date: dailydata.date }))

    return modifiedData;
}
catch (error) {
    console.log(error);
}

}

For Fetching Daily Data of United States use this api https://api.covidtracking.com/v1/us/daily.json

zpreston123 commented 4 years ago

Issue has been resolved in the mathdroid API.