I fetch data from my api, JSON is :
{
"food": [
{
"food": "Not Handle",
"nb": 49
},
{
"food": "Cooked",
"nb": 1
},
{
"food": "Raw",
"nb": 1
},
]
}
My data are stored in my state when the component didMount so this.state.food contain my JSON data
I tried to to render it like this:
render() {
return (
<Row>
{this.state.food &&
this.state.food.map((food) => {
return (
<div >
<Col sm={12} md className="mb-sm-2 mb-0">
<div className="text-muted">{food.food} :</div>
<strong> {food.nb}</strong>
</Col>
</div>)
})}
</Row>
)
}
CompenentDidMount : (getCall is a custom function to fetch)
async componentDidMount () {
const food = await getCall(
`stats/event/count/food?eventRef=${this.props.eventRef}`,
this.props.authToken,
false
);
console.log('DATA', food); // printed my data perfectly
this.setState({ food: food});
}
I think I miss something, because I can't map on this object I get map is not a function, I saw it's only an array ?
expected result is really simple i want to display :
Not handle: 49
Cooked: 1
Raw: 1
componentDidMountmethod ?