我试图使用一个内联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)} />
                ))}
              }
            })()}

推荐答案

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

好了.

React-native相关问答推荐

我们在react钩子中还需要功能性的 setState 方式吗?

加载作为props传递的图像

从 React-Native 应用程序中的另一个类访问静态变量?

react-native alignSelf 中心并拉伸到 maxWidth?

如何在react-native中淡化视图的边缘?

如何手动在抽屉导航底部添加额外的元素(如注销按钮)?

迷失在 Ionic、Cordova 等混合应用程序框架中

Undefined 不是判断 this.state.* 的对象

React Native:fetch request failed with error - TypeError: Network request failed(…)

React Native:无法点击调试菜单

由于端口 8081 sunproxyadmin,无法打包 react native

试图注册两个具有相同名称 ProgressBarAndroid 的视图

将 svg 转换为 react-native-svg

可以react native使用jQuery

如何在 Text ReactNative 中包含 TouchableOpacity

SyntaxError:Strict mode does not allow function declarations in a lexically nested statement on a newly created app

如何将本地文本文件加载到 React Native Project 中的字符串变量中?

react-native run-ios 运行失败: Application is unknown to FrontBoard?

zoom 到指定的标记 react-native-maps

在 React Native 中检测向左滑动