【问题标题】:Hiding an element using conditional statements using RN使用 RN 使用条件语句隐藏元素
【发布时间】:2017-08-28 08:41:40
【问题描述】:

我需要在 touchableOpacity 中显示一个图标,仅当作为参数传递的值使用函数返回为 True 时。

请指导我,因为它显示了 renderIcon() 函数的一些错误。

const CardTitle = ({ titleText, EditButton = false }) => {
   if (EditButton === true) {
   this.state = {
   status: true,
}
   }
 renderIcon() {
if (EditButton) {
  return 
  (<Text style={styles.IconStyle}>{"\ue90b"} </Text>);
}
  }
return (
<View style={styles.container}>
  <Text style={styles.HeadingStyle}>
    {titleText}
  </Text>
  <TouchableOpacity>
    {this.renderIcon()}
  </TouchableOpacity>
</View>
     );
     };   

也可能是语法错误..

【问题讨论】:

    标签: android reactjs react-native react-redux


    【解决方案1】:

    尝试更改您的代码

    {this.renderIcon()}
    

    有了这个

    {EditButton ? <Text style={styles.IconStyle}>{"\ue90b"} </Text> : <View />}
    

    也许这段代码可以解决你的问题

    【讨论】:

      猜你喜欢
      • 2021-10-04
      • 1970-01-01
      • 1970-01-01
      • 2015-12-12
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 2018-11-29
      相关资源
      最近更新 更多