I am working on a react project. I was trying to pass item.id as the argument to the event handler. But I don't know how to send the value as the argument and how to access the value in the method. The program I was doing is shown below. Can someone help me to solve this issue?
class ItemList extends React.Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
render() {
return <div>
{this.props.items.map(item =>
<button key={item.id} item={item} onClick={this.onClick} />
)}
</div>;
}
onClick(itemId) {
console.log('Clicked item:', itemId);
}
}