user2554585 user2554585 - 10 months ago 281
React JSX Question

Call multiple functions onClick ReactJS

I know in vanilla js, we can do


What would be the equivalent for making two function calls onClick in ReactJS?

I know calling one function is like this:


Answer Source

Wrap your two+ function calls in another function/method. Here are a couple variants of that idea:

1) Separate method

var Test = React.createClass({
   onClick: function(event){
   render: function(){
      return (
         <a href="#" onClick={this.onClick}>Test Link</a>

2) Inline

<a href="#" onClick={function(event){ func1(); func2()}}>Test Link</a>

or ES6 equivalent:

<a href="#" onClick={(event) => { func1(); func2();}}>Test Link</a>