我有一个实际上是表格行的组件:
class Row extends PureComponent {
static propTypes = {
user: PropTypes.shape({
id: PropTypes.number.isRequired,
firstName: PropTypes.string,
lastName: PropTypes.string,
email: PropTypes.string,
phone: PropTypes.string
}).isRequired
};
onSelect = event => {
console.log(event);
};
render() {
const { user } = this.props;
return (
<div className="row" onClick={event => this.onSelect(user)}>
<div>{user.id}</div>
<div>{user.firstName}</div>
<div>{user.lastName}</div>
<div>{user.email}</div>
<div>{user.phone}</div>
</div>
);
}
}
如何通过另一个组件(生成表)中的onSelect函数传递事件?