I have a table in which each row has a button that would send a DELETE request to delete that row's data from database:
{
title: '',
render: (record) => {
return (
<Button icon={<DeleteOutlined />} style={{color:'#1890ff', border:'solid 0px'}} onClick={() => showModal(record)}
>
</Button>
)
}
},
Here I'm trying to pass the record data when clicking on the button to a modal. To do that I created a useState hook that would store my table row's data and then I wanted to pass the data to a modal:
const [modalTaskId, setModalTaskId] = useState();
const [visible, setVisible] = useState(false);
const showModal = (record) => {
setModalTaskId(record);
setVisible(true);
};
This is my modal:
<Modal
visible={visible}
onOk={() =>{handleOk()}}
confirmLoading={confirmLoading}
onCancel={handleCancel}
>
<p>{modalText}</p>
</Modal>
And let's say I want to log the modalTaskId when clicking ok on modal:
const handleOk = async () => {
console.log('modalTaskId: ', modalTaskId)
}
But it logs empty for me! So how can I pass data from my table's row to my modal and then use that data when clicking on modal's ok button?