android - 使用 RN 使用条件语句隐藏元素

标签 android reactjs react-native react-redux

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

请指导我,因为它显示了 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>
     );
     };   

这也可能是一些语法错误..

最佳答案

尝试改变你的代码

{this.renderIcon()}

有了这个

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

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

关于android - 使用 RN 使用条件语句隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45914976/

相关文章:

Android USB 配件与 Linux 系统通信

reactjs - React propType 无法读取未定义的属性

javascript - 如何在类组件中处理从父级事件处理程序传递到子级事件处理程序的附加参数

javascript - 在 react 导航中刷新 contentComponent

reactjs - React Native - 退出应用程序时调用方法

android - Android 均衡器中的频段数

android - 如何以特定的固定时间间隔唤醒我的 android 应用程序?

java - 无法使用共享首选项保存游戏高分?

javascript - 如何在 redux reducer 中有条件地 $merge 或 $set 嵌套数据?

ios - 网络错误 - React Native iOS 模拟器