Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native display View depending on conditional

In my render method I'd like to display one of two View components depending on a conditional that's in my props. e.g:

render() {
  return(
    <View>
      <View>View A</View>
      <View>View B</View>
    </View>
  );
}

Where the conditional is this.props.myConditional. If false, show A, if true, show B...


1 Answers

It's actually pretty easy

render() {
  return <View>
    {this.props.myConditional ? <View>View B</View> : <View>View A</View>}
  </View>
}
like image 87
Mμ. Avatar answered Jul 16 '26 03:07

Mμ.