const [data, setData] = useState(null);
useEffect(() => {
const getData = async () => {
await fetch('http://localhost:4000/data')
.then(res => res.json())
.then(fetchedData => {
setData(fetchedData);
console.log(fetchedData)
})}
getData();
}, [])
return (
<div className="App">
<Header />
<ul>{ data &&
data.map((item, index) => {
item.map(object => {
Object.keys(object).map((key) =>
(<li key={index}>{object[key]}</li>)
);
})
})}</ul>
</div>
the data structure is like this:
[[{'sum': 210}], [{'total': 210}], [{'free': 210}], [{'discounted': 210}]]
When I log the data in the console I see it but I see nothing in the UI just <ul></ul>