You get a bonus - 1 coin for daily activity. Now you have 1 coin

What is a common mistake that calls a function every time a component renders? in REACT

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

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Scripting client side JavaScript, jqvery, BackBone"

Terms: Scripting client side JavaScript, jqvery, BackBone