The code below shows 2 functions that SHOULD render components to the screen. When I map through an array, the components render. The problem is when I attempt to map through an array within an object in an array, the components won't render.
So let's imagine we have this dataset:
const categories = [
{
title: "Burgers",
items: [
{
item_number: 0,
name: "Cheese Burgers"
},
{
item_number: 1,
name: "Double Cheese Burgers"
},
{
item_number: 2,
name: "Triple Cheese Burgers"
}
]
}
];
And then we have this render function:
render() {
const { backgroundImage, menuIndex } = this.props.screenProps;
return (
<View>
{/*THIS DOES RENDER*/}
{categories ? (
categories.map((category, i) => (
<Card key={i} image={backgroundImage}>
<Text style={{ marginBottom: 10 }}>{category.title}</Text>
</Card>
))
) : (
<ActivityIndicator style={styles.center_screen} />
)}
{/*THIS DOES NOT RENDER*/}
{categories ? (
categories[menuIndex].items.map((item, i) => {
<View key={i}>
{console.warn(item.name)}
<Text>{item.name}</Text>
</View>;
})
) : (
<ActivityIndicator style={styles.center_screen} />
)}
</View>
);
}
}
The variable "categories" is called from an API and while it's in route the Activity Indicator shows. When it's not null, I'm able to map through the array and display text from each object. However, when I try to map through an array within an object of an array, I'm not able to render text to the screen. When I log the warning to the screen, I'm able to see the "item.name" but not within a Text component.
How and why is this happening?