仅当作为参数传递的值为 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/