How to pass a parameter to an event handler or callback?

Technology CommunityCategory: ReactHow to pass a parameter to an event handler or callback?
VietMX Staff asked 4 years ago

You can use an arrow function to wrap around an event handler and pass parameters:

<button onClick={() => this.handleClick(id)} />

This is equivalent to calling .bind as below,

<button onClick={this.handleClick.bind(this, id)} />