You should notice that this depends on how the function is called. That is: when the function is called as a method of an object, its this set to the object to which the method is called.
this is available in the JSX context as a component object, so you can call the desired method with the built-in this method.
If you just pass the link to the function / method, it seems that the reaction will call it as an independent function.
onClick={this.onToggleLoop} // Here you just passing reference, React will invoke it as independent function and this will be undefined onClick={()=>this.onToggleLoop()} // Here you invoking your desired function as method of this, and this in that function will be set to object from that function is called ie: your component object
Jakub Kutrzeba Sep 05 '19 at 18:09 2019-09-05 18:09
source share