簡體   English   中英

反應,處理另一個函數調用的模式中的按鈕單擊

[英]React, handle a button click from a modal called from another function

如何捕獲模態中某些按鈕的單擊以返回truefalse

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM