So my code is:
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
myArray: [
{id:1, continent:[
{id:1, name: 'Russia'},
{id:2, name: 'Germany'},
{id:3, name: 'Poland'}
]},
{id:2, continent:[
{id:1, name: 'China'},
{id:2, name: 'India'},
{id:3, name: 'Bangladesh'}
]},
{id:3, continent:[
{id:1, name: 'Brazil'},
{id:2, name: 'Peru'},
{id:3, name: 'Chile'}
]}
],
otherValue: 23
}
}
subBoardList(id){
return this.state.myArray[id].map((continent) => {
return(
<View>
<Text>{continent.name}</Text>
</View>
)
})
}
render() {
return (
{this.subBoardList(2)}
);
}
}
I want to display the content of the continent array of which id is passed to the subBoardList function. How do I do that?
Error:
TypeError: undefined is not an object (evaluating 'this.state.myArray[id].map')