This is the link to the api which I have been using. API link here
import React, { useEffect, useState } from "react";
const Statewise = () => {
const [data, setData] = useState([]);
const getCovidData = async () => {
const res = await fetch('https://data.covid19india.org/data.json');
const actualData = await res.json();
console.log(actualData.statewise);
setData(actualData.status);
}
useEffect(() => {
getCovidData();
}, []);
return (
<>
<div className="container-fluid mt-5">
<div className="main-heading">
<h1 className="mb-5 text-center">COVID-19 Dashboard</h1>
</div>
<div className="table-responsive">
<table className="table table-hover">
<thead className="thead-dark">
<tr>
<th>State</th>
<th>Confirmed</th>
<th>Recovered</th>
<th>Deaths</th>
<th>Latest</th>
<th>Active</th>
</tr>
</thead>
<tbody>
{
data.map((currElem, ind) => {
return (
<tr key={ind}>
<th>{currElem.state}</th>
<td>{currElem.confirmed}</td>
<td>{currElem.recovered}</td>
<td>{currElem.deaths}</td>
<td>{currElem.lastupdatedtime}</td>
<td>{currElem.active}</td>
</tr>
)
})
}
</tbody>
</table>
</div>
</div>
</>
)
}
export default Statewise;
The error shown on the console is shown below. Please provide way-outs. Due to this error, the page is not rendered and no data can be seen.
Uncaught TypeError: Cannot read properties of undefined (reading 'map') at Statewise (statewise.js:37:1) at renderWithHooks (react-dom.development.js:16305:1) at updateFunctionComponent (react-dom.development.js:19588:1) at beginWork (react-dom.development.js:21601:1) at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1) at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1) at invokeGuardedCallback (react-dom.development.js:4277:1) at beginWork$1 (react-dom.development.js:27451:1) at performUnitOfWork (react-dom.development.js:26557:1) at workLoopSync (react-dom.development.js:26466:1)
I tried rewriting the names of API but that did not work. I did not get a solution. I tried to do the mapping process again but it shows the same error.