Good day!
Is it possible to trigger multiple functions on the onClick event ?
I would like when the user clicks on my button to setState and then run a function. I managed to update my state but I am not sure how to proceed to add the second step which would be to run my function called "goToOrderTemplate()"
<button
type="button"
className="btn btn-primary"
style={{ width: 250 }}
onClick={() =>
this.setState({
auth: this.passwordValidation()
})
}
>
Any help woul dbe greatly appreciated!
setState
takes a second parameter, which is a callback that gets called back when the state was set. You should use that if goToOrderTemplate
depends on the state being set:
this.setState({
auth: this.passwordValidation(),
}, goToOrderTemplate)
In the general case that you want to call two functions, just do that:
onClick={() => {
this.setState({
auth: this.passwordValidation(),
});
goToOrderTemplate();
}}
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