I have the following two components:
class A extends Component {
_onDelete(id) {
this.props.deleteItem(id);
}
render() {
return <B onDelete={this._onDelete}/>;
}
}
class B extends Component {
const onDelete= {this.props};
let id = this.props.item.id;
render() {
return <div onClick={onDelete}>Hello</div>;
}
}
I don't want to bind this (component B context) to the function, I only want to pass id to _onDelete.
I tried these approaches:
Arrow function:
return <div onClick={() => onDelete(id)}>Hello</div>;
context in _onDelete changes to B, and I don't have access to this.props.deleteItem anymore.
Passing by event:
return <div onClick={onDelete} itemId={id}>Hello</div>; _onDelete(event) { this.props.deleteItem(event.target.itemId); }
event.target.itemId is undefined
How can I pass the itemId to A's function, without binding this to it ?