<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>; }