简体   繁体   中英

How to pass a variable as props inside the scope of another function's component

I want to get a variable, called id in this case, and pass it to the onConfirm event... however, as you can see actually it is getting called by another's function call in setAlert How can I do that?

const warningWithConfirmAndCancelMessage = (id) => {
    setAlert(
      <ReactBSAlert
        warning
        style={{ display: 'block', marginTop: '-100px' }}
        title='Are you sure?'
        onConfirm={(id) => {
          successDelete();
          handleDelete(id);
        }}
        onCancel={() => cancelDelete()}
        confirmBtnBsStyle='success'
        cancelBtnBsStyle='danger'
        confirmBtnText='Yes, delete it!'
        cancelBtnText='Cancel'
        showCancel
        btnSize=''
      >
        You will not be able to recover this imaginary file!
      </ReactBSAlert>
    );
  };

don't pass id as parameter to onConfirm function

onConfirm={() => {
    successDelete();
    handleDelete(id)
}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM