DEV Community

Discussion on: How to pass extra params to your handlers functions with React?

Collapse
 
silvestricodes profile image
Jonathan Silvestri

Is this a good case for some event delegation? Perhaps assigning a click handler to the parent which should be able to give you all the children if you click on one, and then writing appropriate guard clauses to only do things with the info of the DOM node you care about.

Collapse
 
eatsjobs profile image
Pasquale Mangialavori • Edited

You mean somenthing like this?yeah a could add it in the article. thanks

class MyLi extends PureComponent {
_onPress = (evt) => {
const { item, onPress } = this.props;
onPress(evt, item);
}
render() {
return <li onClick={this._onPress}>{this.props.children}</li>
}
}