Practice
You must make sure the function is not called when you pass a function as a parameter.
render () { // Wrong: handleClick is called instead of being passed as a reference!
return < button onClick = { this . handleClick () } > { ' Click Me ' } </ button > }
Instead, pass the function itself without parentheses:
render () { // Correct: handleClick is passed as a reference!
return < button onClick = { this . handleClick } > { ' Click Me ' } </ button > }
Comments