反应本地条件渲染 [英] react native conditional rendering
本文介绍了反应本地条件渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用内联if语句来检查数据是否存在以及是否确实要显示它.该代码当前位于我的渲染返回块中.
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)} />
))}
}
})()}
推荐答案
render(){
return(
<View>
{this.state.error && <Text style={{ color: 'red' }}>{this.state.errorMessage}</Text>}
<Text>Hello World!</Text>
</View>
);
}
去那里.
这篇关于反应本地条件渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文