[英]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?我想获取一个变量,在这种情况下称为 id ,并将其传递给 onConfirm 事件......但是,正如您所看到的,实际上它正在被 setAlert 中的另一个 function 调用调用我该怎么做?
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不要将 id 作为参数传递给 onConfirm function
onConfirm={() => {
successDelete();
handleDelete(id)
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.