Warm tip: This article is reproduced from serverfault.com, please click

react native conditional rendering

发布于 2017-02-07 11:09:11

I am trying to use an inline if statement to check if a piece of data exists and if it does to display it. this code is currently sitting in my render, return block.

the problem I am having is that using this, the content is no longer being rendered

{(() => {
              if (this.props.data.size) {
                <Text style={styles.headerLabel}>Sizes</Text>
                {(this.props.data.size||[]).map((section,i) => (
                  <AddToCartRow key={i} data={section} productName={this.props.data.name} value={Config.priceToPriceWithCurrency(section.price)} />
                ))}
              }
            })()}
Questioner
Boss Nass
Viewed
0
Ata Mohammadi 2017-10-25 23:02:39

render(){
  return(
    <View>
    {this.state.error && <Text style={{ color: 'red' }}>{this.state.errorMessage}</Text>}
    <Text>Hello World!</Text>
    </View>
  );
}

There you go.