I have added a function to the onPress
method but the function is automatically triggered on loading the app. Am I doing something wrong?
<TouchableHighlight onPress={this.showMenu()}>
<View></View>
</TouchableHighlight>
showMenu(){
this.state.showMenu = true;
}
You are doing it wrong. You should only bind the method on onPress. But you are calling it. Change the onPress as
onPress={this.showMenu.bind(this)}
You are actually executing the function from within the onPress directive.
You should use
onPress={this.showMenu}
Without the parenthesis, the function will not trigger at loading, only when the user triggers it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With