Answers for "onclick function executing automatically react"

1

react why onclick property function trigger without click

change:
  <button type="button" onClick={this.myFunction(argument)}> myButton </button>
  
to this: 
  <button type="button" onClick={this.myFunction.bind(this, argument)}> myButton </button>
Posted by: Guest on June-14-2020
0

react onclick action starts automatically

// Credit to: Long Nguyen
// Source: https://stackoverflow.com/questions/33846682/react-onclick-function-fires-on-render

// Because you are calling that function instead of passing the function 
// to onClick, change that line to this:

<button type="submit" onClick={() => { this.Function }}>Submit</button>

// => called Arrow Function, which was introduced in ES6,
// and will be supported on React 0.13.3 or upper.
Posted by: Guest on August-21-2021

Code answers related to "onclick function executing automatically react"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language