edz edz - 28 days ago 4
Android Question

Hiding an element using conditional statements using RN

I need to display an Icon in the touchableOpacity Only if the value passed as parameter is True using a function return.

Please guide me as it shows some error with the renderIcon() function.

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>
);
};


It could be some syntatical error too..

Answer Source

try to change your code

{this.renderIcon()}

with this

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

Maybe this code can fix your problem