I am tired print out sub array data form an object in render()..
data object JSON:
{
"genres": [
{
"id": 27,
"name": "aa"
},
{
"id": 878,
"name": "bb"
},
{
"id": 28,
"name": "cc"
},
{
"id": 53,
"name": "dd"
}
],
"status": "Released",
"tagline": ""
}
MyMainScreen.js
render() {
return (
<Container>
<Content style={{marginLeft:0,marginRight:0}}>
<InfoSection key={this.state.data.id} info={this.state.data}/>
</Content>
</Container>
);}
InfoSection .js
const InfoSectionCard = ({ info }) => (
<View>
<Text style={styles.cardGenreItem}>{info.genres}</Text>
</View>
);
export default InfoSectionCard;
I was using .map to solve this.. not it does work usually.
It works print out all JSON object when usingJSON.stringify(obj)
When I try
<Text style={styles.cardGenreItem}>{info.genres}</Text>
the react error message are Invariant Violation: Objects are not valid as a React child (found: object with keys {id, name}). If you meant to render a collection of children, use an array instead.
But then add the '.map'
info.genres.map(item =><Text style={styles.cardGenreItem}>{item.name}</Text>)
the react error message are TypeError: undefined is not an object(evaluating 'info.genres.map')