如何在另一个函数的组件范围内将变量作为道具传递

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

我想获取一个变量,在本例中称为 id,并将其传递给 onConfirm 事件...但是,正如您所看到的,实际上它正在被 setAlert 中的另一个函数调用调用 我该怎么做?

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

不要将 id 作为参数传递给 onConfirm 函数

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