Interested-Learner
Interested-Learner

Reputation: 27

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..

Upvotes: 1

Views: 53

Answers (1)

Maulana Prambadi
Maulana Prambadi

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

Related Questions