I am calling function from a button onClick with two parameters. In the function I want to set the values in existing form and send the udpated value to action also with the function parameters. can't acheive this using hook useEffect. Struck with parameter passing to useEffect.
I have searched many posts and stack overflow questions but can't find a solution for this setState delay issue in hook.
<td onClick={() => update_intime(data._id, data.patient_id.name)}>
<div>{<FaCheck />}</div>
</td>
I am calling the function from above code and sending two parameters i want to set value to existing formData and send the updated value to actions. If i use useEffect after updating formdata how can i pass function parameters to that
const update_intime = (id, name) => {
setFormData({ ...formData, in_status: 'true' });
swal({
title: 'Are you sure?',
text: `You want to Check in the Appointment of ${name}!`,
icon: 'warning',
buttons: ['No', 'Yes'],
dangerMode: true,
}).then(function (isConfirm) {
if (isConfirm) {
edit_appointment(id, formData, navigate, 'checkin');
}
});
};
by the below answer i got a workaround like
const update_intime = (id, name) => {
setFormData({ ...formData, in_status: 'true' });
let data = formData;
data.in_status = 'true';
console.log(data)
swal({
title: 'Are you sure?',
text: `You want to Check in the Appointment of ${name}!`,
icon: 'warning',
buttons: ['No', 'Yes'],
dangerMode: true,
}).then(function (isConfirm) {
if (isConfirm) {
edit_appointment(id, data, navigate, 'checkin');
}
});
};
Is it a correct or proper way to achieve the solution?