[英]Trigger a function in another component on click a button from a different component in React
[英]React, handle a button click from a modal called from another function
如何捕獲模態中某些按鈕的單擊以返回true
或false
?
handleSubmitSaveConfigurations = async (row) => {
const { scadaValidation } = this.props;
const result = await scadaValidation(11);
if (result.statusCode !== 200) {
// Opens the modal to ask if you really want to save
this.setState({openSimpleModal: true});
this.setState({contentSimpleModal: this.warningModal()});
// Here I have to catch if the modal click yes or no.
// In case yes, do nothing and continue with the code
// But in case "no" returns false and stops
}
// If result.statusCode === 200 returns true
return true;
}
warningModal = () => (
<div>
Do you want to save?
<Button id="btnClose" onClick={() => this.handleModalClickClose()}>No</Button>
<Button id="btnSave" onClick={() => this.handleModalClickClose()}>Yes</Button>
</div>
);
handleModalClickClose = () => this.setState({ openSimpleModal: false });
<Button id="btnClose" onClick={() => this.handleModalClickClose(this.state.openSimpleModal)}>No</Button>
<Button id="btnSave" onClick={() => this.handleModalClickClose(this.state.openSimpleModal)}>Yes</Button>
handleModalClickClose = value => this.setState({ openSimpleModal: !value});
我將函數重命名為toggleModal = value => this.setState({open:!value});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.