Why passing e.target.name is not working here in React

时间:2019-05-31 11:31:53

标签: javascript reactjs

I want to pass the remove method and remove the item from the array. Here's the code

https://codesandbox.io/embed/heuristic-star-chie9

remove(item,e){
    const x = e.target.name
    console.log(x)
    this.setState((prevState) => {
      return {
        friends : prevState.friends.x.filter((k) => (k.name !== item.name) )
      }
    } )
}
<button name='deactive' onClick={() => {props.remove(item)}}> REMOVE 
</button>

1 个答案:

答案 0 :(得分:0)

You have to pass the event like that :

<button name='deactive' onClick={(event) => {props.remove(item, event)}}> REMOVE 
</button>
相关问题