React Pattern: Extract Child Components to Avoid Binding
Cory House
1.6K35

Your solution is perfectly fine. For other reasons, I generally favor extracting anything returned by a map.

By I don’t think you need to extract to solve the problem. Why not this…

deleteUser = user => {    
this.setState(prevState => {
return { users: prevState.users.filter( u => u.id !== user.id)}
})
}

And…

<input
type="button"
value="Delete"
onClick={this.deleteUser}
/>

Correct me if I’m wrong, but this should work and not rebind.

https://gist.github.com/timscott/b4b13e450f98e47d3c4e246f27f13dfb

Like what you read? Give Tim Scott a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.