I have a same field for creating and updating the form using modal , the creation is working fine, while for the updating the latest changes are not updating , infact I am getting the previous value only , let me know where I am missing here .
Creation and Updating:
const createVendor = async () => {
setEditMode(false);
const data = { contactPerson, contactNumber, email };
try {
const response = await addingVendor(data);
setMessage(response.data.message);
forceUpdate(), handleClose();
} catch (error) {
throw error;
}
};
const updateVendor = async () => {
setEditMode(true);
const data = { contactPerson, contactNumber, email };
try {
const response = await updatingVendor(vendorId, data);
console.log(response);
setMessage(response.data.message);
forceUpdate(), handleClose();
} catch (error) {
throw error;
}
};
This is where I am triggering the modal for update:
const [inputValue, setInputValue] = useState({
contactPerson: '',
contactNumber: '',
email: '',
});
const showUpdateVendor = (data) => {
setOpenUpdate(true);
setInputValue({
contactPerson: data.contactPerson,
contactNumber: data.contactNumber,
email: data.email,
});
setVendorId(data._id);
};
and here is the modal component where i am passing via props:
<SideModal
{...inputValue}
open={openUpdate}
onClose={() => setOpenUpdate(!openUpdate)}
title='Update Vendor'
handleChange={handleChange}
editMode={editMode}
onSubmit={updateVendor}
isLoading={isupdatingVendor}
/>

