j.doe
j.doe

Reputation: 4859

Detect click on buttons

I am trying to create a header in my app. I installed the module react-native-elements and used their header. Every thing is working fine but I am not able to detect the clicks on the header. I get a syntax error when I tried to do this

leftComponent={{ icon: 'menu', color: '#4c788', onPress={() => this.myFunction()} }}

or

leftComponent={{ icon: 'menu', color: '#4c788', onPress= this.myFunction()} }}

or

leftComponent={{ icon: 'menu', color: '#4c788', onPress={() => myFunction()} }}

or

leftComponent={{ icon: 'menu', color: '#4c788', onPress= myFunction()} }}

do you have an idea on how to achieve this?

Upvotes: 0

Views: 80

Answers (1)

Arman Charan
Arman Charan

Reputation: 5797

You are setting your onPress value using = instead of :

Try:

leftComponent = {
  { 
    icon: 'menu', 
    color: '#4c788', 
    onPress: () => this.myFunction()
  } 
}

Upvotes: 2

Related Questions