Reputation: 27
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..
Upvotes: 1
Views: 53
Reputation: 1041
try to change your code
{this.renderIcon()}
with this
{EditButton ? <Text style={styles.IconStyle}>{"\ue90b"} </Text> : <View />}
Maybe this code can fix your problem
Upvotes: 1