I'm super new to React.js in general and want to use this api here: https://covidtracking.com/api/v1/states/current.json to create a table with up-to-date COVID-19 data from American states. Problem is, when I render the app, I can't seem to upload the data into the table. Any help would be appreciated, thanks.
import React, { useMemo, useState, useEffect } from "react";
import axios from "axios";
import Table from "./Table";
import "./App.css";
function App() {
const [loadingData, setLoadingData] = useState(true);
const columns = useMemo(() => [
{
Header: "State",
accessor: "show.state",
},
{
Header: "Positive Cases",
accessor: "show.positive",
},
{
Header: "Recovered Cases",
accessor: "show.recovered",
},
{
Header: "Deaths",
accessor: "show.death",
},
{
Header: "Total Tested",
accessor: "show.total",
}
]);
const [data, setData] = useState([]);
useEffect(() => {
async function getData() {
await axios
(.get("https://covidtracking.com/api/v1/states/current.json")
.then((response)) => {
console.log(response.data);
setData(response.data);
setLoadingData(false);
});
}
if (loadingData) {
getData();
}
}, []);
return (
<div className="App">
{loadingData ? (
) : (
<Table columns={columns} data={data} />
)}
</div>
);
}
export default App;