Reputation: 977
Working with React Native, unable access the brand
property of my object and of course less brand.name
.
Does anyone know what might be happening? Thank you
Code:
<CardItem bordered style={ styles.cardItem }>
<Text style={{ padding:20 }} >{this.state.beer.brand.name}</Text>
</CardItem>
Object:
Upvotes: 2
Views: 2897
Reputation: 33994
You should do conditional check before accessing nested keys directly
Something like
const { beer } = this.state;
return(
<div>
<CardItem bordered style={ styles.cardItem }>
{beer && beer.brand && <Text style={{ padding:20 }} >{ beer.brand.name}</Text>}
</CardItem>
</div>
)
Upvotes: 4