I am trying to map an array of objects within an object and I can't seem to get it working. My code's goal is to map and then display the content within the "menu" array.
Here is the structure of the object (logged to console from a state).
Object {
"id": 1,
"img": "https://cuisinederue.org/wp-content/uploads/2019/08/Greg2.png",
"menu": Array [
Object {
"description": "Les prix sont défini à la tête du client",
"name": "Greg's Burger",
"price": 1,
},
Object {
"description": "Les prix sont défini à la tête du client",
"name": "Poutine double cheese bacon",
"price": 1,
},
Object {
"description": "Les prix sont défini à la tête du client",
"name": "Cône de poulet pop corn et frites maison",
"price": 1,
},
Object {
"description": "Les prix sont défini à la tête du client",
"name": "Grilled cheese Philly steak",
"price": 1,
},
Object {
"description": "Les prix sont défini à la tête du client",
"name": "Poutine Philly cheese steak",
"price": 1,
},
Object {
"description": "Les prix sont défini à la tête du client",
"name": "Boulette de mac'n'cheese",
"price": 1,
},
],
"name": "Greg's dinner",
"type": "SOUTHERN COMFORT",
}
And here is the code that I'm trying to get to work: (specifically the details.menu.map part)
const Details = ({navigation, idTruck}) =>{
const [details, setDetails] = useState([]);
const [detailsDone, setDetailsDone] = useState(false);
const getDetails = () => {
fetch("https://foodtrack-420kbc-lg.herokuapp.com/trucks/1").then(res => res.json()).then(resp => setDetails(resp));
}
if(!detailsDone)
{
getDetails();
setDetailsDone(true);
}
console.log(details);
return (
<View style={styles.container}>
<Header title='Details'></Header>
<Image name="logo" style={styles.detailsImage} source={{uri: details.img}}></Image>
<Text name="nom">{details.name}</Text>
<Text name="style">{details.type}</Text>
{
details.menu.map(({description, name, price}) =>
<View style={styles.container}>
<Text name="nom">{name}</Text>
<Text name="prix">{price}</Text>
<Text name="desc">{description}</Text>
</View>
)
}
</View>
)
}
The error I am getting is: TypeError: undefined is not an object (evaluating 'details.menu.map'
Any help is greatly appreciated!
details.menu.map((detail) =>and<Text name="nom">{detail.name}</Text>