I'd like to create a menu based on a 2 dimensional Array: title and icon name.
Here's what I tried:
class Menu2 extends React.Component{
constructor(props) {
super(props);
this.state = { Items: [['Home','home'],['User','user'],['Messages','envelope'], ['Finances','wallet'], ['Meal','silverware-fork-knife']]}
}
render(){
<View style={styles.menu}>
{this.state.Items.map((Items,i) => {
return(
<TouchableOpacity style={[styles.menu_item,styles.menu_item]} onPress={() => {this.props.navigation.navigate(Items[i][0]);}}>
<FontAwesome name={Items[i][1]} size={40} color="#fff"/>
<Text style={styles.menu_text}>{Items[i][0]}</Text>
</TouchableOpacity>
)
})};
</View>
}
}
export default Menu2
Error returned is "TypeError undefined is not an object (evaluating 'Items[i][1]')"
What I was expecting is that "i" would by the iteration 0, 1, 2, 3, 4 (looping 5 times in my case) of my array and so Items[i][0] = the title and Items[i][1] = the icon name. But I couldn't make it work like I would have liked.
Any ideas?