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

if statement- React 原生条件渲染

(if statement - react native conditional rendering)

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

我正在尝试使用内联 if 语句来检查一条数据是否存在以及是否显示它。这段代码目前位于我的渲染、返回块中。

我遇到的问题是使用这个,内容不再被呈现

{(() => {
              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>
  );
}

你去吧。