import React , {useState, useEffect} from 'react'
import styles from './Statewise.css';
const Statewise = () => {
const [data, setData]=useState([]);
const getCData = async () => {
const res = await fetch('https://api.covid19india.org/data.json');
const actualData = await res.json();
console.log(actualData.Statewise);
setData(actualData.Statewise);
}
useEffect(() => {
getCData();
}, [])
return (
<div className="bts">
<div className="container-fluid mt-5">
<div className="main-heading">
<h1 className="mb-5">
<span className="font-weight-bold">INDIA COVID 19 TRACKER</span>
</h1>
</div>
<div className="table-responsive">
<table className="table table-hover">
<thead className="thead-dark">
<tr>
<th>States</th>
<td>Confirmed</td>
<td>recovered</td>
<td>death</td>
<td>active</td>
<td>updated</td>
</tr>
</thead>
<tbody>
{
data.map((curElem) => {
return(
<tr key={curElem.id}>
<th>{curElem.state}</th>
<td>{curElem.Confirmed}</td>
<td>{curElem.recovered}</td>
<td>{curElem.deaths}</td>
<td>{curElem.active}</td>
<td>{curElem.lastupdatedtime}</td>
</tr>
)
})
}
</tbody>
</table>
</div>
</div>
</div>
)
}
export default Statewise;
Not able to extract values from the api.
- I have tried data && data.map(... this is also not working.
- I have tried adding the load and error methods but then also the main data from the api id not displayed. please suggest solutions .