When I press the button, it supposed to navigate to another page and it also increase the view count.
But I can't figure out anyway to implement them at the same time.
This is my code:
<Button onPress={Actions.ideaOnClick}>
<Button onPress={() => this.setState({views: ++this.state.views})}>
To call multiple functions when onPress is clicked with React Native, we can assign onPress to a function that calls all the functions. to define the onPress function that calls foo , bar , and baz . Then we set the onPress prop to the onPress function.
Call Multiple Functions onClick in Reactlog('hello!' ); } function waveHello() { console. log('wave'); } return ( <div> <button onClick={() => { greeting(); waveHello(); }}> I'm a button </button> </div> ); } export default App; The example above may look similar to the first solution, but it's very different.
Just create a function that does both things. No other way around it (if a lib has a utillity for that it would do something similar) since onPress
is a single function.
<Button onPress={() => {
Actions.ideaOnClick()
this.setState({views: ++this.state.views})
}}>
yourFunction(){
Actions.ideaOnClick();
this.setState({views: ++this.state.views});
}
<Button onPress={this.yourFunction.bind(this)}}>
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