I am trying to bind 2 functions to the same onClick event in the reactjs button.
I saw a few examples here but they did not work for me; either the syntax is different or my code logic just won't support two functions inside one button click. Here is an example of what I'm doing:
class Example extends Component {
state = {
test:1
}
//function 1
add() {
this.setState({
test: this.state.test+1
});
}
//function 2
somefunc() {
// does smthng
}
render() {
return (
<div>
<Button color = 'success'
onClick={this.add.bind(this)}>+1
</Button>
</div>
)
}
}
The code above works. But I need to be able to add the second (somefunc()) function to that onClick. Something like this:
onClick={() => {this.add.bind(this); this.somefunc.bind(this)}}
Is it possible with bind? If not, could you please explain how to call a function without the bind.