单击从React组件到另一个组件的渲染

时间:2018-07-19 14:18:36

标签: javascript reactjs

我有一个实际上是表格行的组件:

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函数传递事件?

0 个答案:

没有答案