React passing parameter via onclick event using ES6 syntax

前端 未结 8 892
死守一世寂寞
死守一世寂寞 2020-12-04 06:34

How to pass extra parameters to an onClick event using the ES6 syntax?

For instance:

handleRemove = (e) => {

}

render() {
     
8条回答
  •  不知归路
    2020-12-04 07:08

    Something nobody has mentioned so far is to make handleRemove return a function.

    You can do something like:

    handleRemove = id => event => {
      // Do stuff with id and event
    }
    
    // render...
      return 

    However all of these solutions have the downside of creating a new function on each render. Better to create a new component for Button which gets passed the id and the handleRemove separately.

提交回复
热议问题