【发布时间】:2019-07-11 17:37:21
【问题描述】:
在我的父组件中,我有一个名为 handleDocumentSubmission 的函数,我想将它传递给子组件。
handleDocumentSubmission = input => async (e) => {
console.log("fired");
然后我像这样渲染以下组件。我使用相同的函数名。
<FrontConfirm
nextStep={this.nextStep}
handleReview={this.handleReview}
values={values}
handleDocumentSubmission={this.handleDocumentSubmission}
/>
现在在我的子组件中,我想通过单击按钮从子函数调用此函数。
continue = () => {
console.log("clicked", this.props);
this.props.handleDocumentSubmission("front");
};
<Button onClick={this.continue}
variant="contained" color="primary">
Confirm
</Button>
现在,我可以通过具有我的 handleDocumentSubmission 功能的道具看到单击的控制台日志。但是父函数console.log("fired") 的console.log 没有被调用。
【问题讨论】:
-
当您使用异步函数时,您应该在
continue方法中使用await this.props.handleDocumentSubmission("front");
标签: javascript reactjs ecmascript-6