React passing parameter via onclick event using ES6 syntax

前端 未结 8 877
死守一世寂寞
死守一世寂寞 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:07

    I am using React-Bootstrap. The onSelect trigger for dropdowns were not allowing me to pass data. Just the event. So remember you can just set any values as attributes and pick them up from the function using javascript. Picking up those attributes you set in that event target.

        let currentTarget = event.target;
        let currentId = currentTarget.getAttribute('data-id');
        let currentValue = currentTarget.getAttribute('data-value');
    

提交回复
热议问题