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>
答案 0 :(得分:0)
You have to pass the event like that :
<button name='deactive' onClick={(event) => {props.remove(item, event)}}> REMOVE
</button>