function Graph() {
const [tcases, setCases] = useState([]);
const [recovered, setRecovered] = useState([]);
const [deaths, setDeaths] = useState([]);
useEffect(() => {
axios
.get("https://disease.sh/v3/covid-19/historical/all?lastdays=all")
.then((res) => {
setCases(Object.values(res.data.cases));
setRecovered(Object.values(res.data.recovered)));
setDeaths(Object.values(res.data.deaths)));
})
.catch((err) => {
console.log(err);
});
}, []);
The code above is showing an error stating that cases, recovered, and deaths are undefined.
For the API used, please click here to see the API. I need the data in the following format. Can someone assist me with this? :)
tcases=[555,654,941...........]
recovered=[17,18,26.........]
deaths=[28,30,36...........]
Thank you!