0
changed={(event) => this.nameChangedhandler(event, person.id)} 

is it correct, that if I didnt need to pass person.id or any other argument to the method, that I could have written it like:

changed={(event) => this.nameChangedhandler(event)} 

and is it the the same like:

changed={this.nameChangedhandler} 

??

because the event from onChanged(which is in the component which gets it as a prop, see below) is automatically passed?

here the props in the component:

<input type="text" onChange={props.changed} value={props.name}/>
Michael
  • 947
  • 7
  • 17

2 Answers2

0

Yes, both are same.

changed={(event) => this.nameChangedhandler(event)} 
changed={this.nameChangedhandler}

As changed function will receive event as first argument So you can use arrow function or direct function.

If you want to pass id you can use bind or arrow function. If you use bind then id will be received as first argument.

Jitesh Manglani
  • 495
  • 5
  • 12
0

changed={(event) => this.nameChangedhandler(event)} is the arrow function syntax and if you refer to a method without () after it, such as changed={this.nameChangedhandler}, you should bind that method. If calling bind annoys you, there are two ways you can get around this. If you are using the experimental public class fields syntax or above arrow function.Refer more here https://reactjs.org/docs/handling-events.html

Aravind S
  • 2,347
  • 2
  • 12
  • 21