将道具从组件传递到静态方法

时间:2018-07-31 07:32:30

标签: javascript reactjs

  <Modal onToggleModal={this.onToggleModal}>
    <Modal.Header onToggleModal={this.onToggleModal}>
      <h1>Modal header</h1>
    </Modal.Header>
    <Modal.Body>
      <ProductDescription data={this.props.data} />
    </Modal.Body>
    <Modal.Footer>
      <h1>Modal footer</h1>
      <button type="button" onClick={this.props.onAddToCart}>
        Buy now
      </button>
    </Modal.Footer>
  </Modal>

是否可以将onToggleModal的{​​{1}}方法直接传递给Modal(这是返回组件的静态方法),因为我无法访问Modal.Header来自this.props静态方法中的内容?

模态成分

Modal

ModalHeader组件

export default class Modal extends React.Component<IProps> {
  static Header = props => <ModalHeader onToggleModal={props.onToggleModal}>{props.children}</ModalHeader>; }

0 个答案:

没有答案