I'm trying to render a Table, but I'm getting a render error, I looked up other stack's questions and there was suggested that I should use map for returning object array values. I also used render inside map. My object looks like this:
[
{
amount_left: "100",
category: "vegtable",
food_name: "potatos",
price: "1",
type: "salty"
},
{
amount_left: "100",
category: "cheese",
food_name: "cheese",
price: "0.5",
type: "salty"
},
...
]
My code.
import React, { Component } from 'react';
import { Table } from 'reactstrap';
class Meals extends Component {
getMeals = async () =>{
const api_call = await fetch(`http://127.0.0.1/RFIDSys/rfid_handler.class.php?action=getAllMeals`);
const data = await api_call.json();
console.log(data[0].food_name) // returns potatos
return data.map((item,i) => {
return (<tr><td>{item.food_name}</td></tr>)
})
}
render(){
return (
<div>
<Table>
<tbody>
{this.getMeals()}
</tbody>
</Table>
</div>
);
}
}
export default Meals;
Cant see what's wrong, I'm getting "Objects are not valid as a React child (found: [object Promise]).If you meant to render a collection of children, use an array instead." error.
The error that suggest that use array instead, ain't I using arrays in map function or it's still an object what I'm returning?
console.log(data[0].food_name)return?