Reputation: 528
I need to set initial values after form submission. this is the sample code for my save fucntion
const [form, setForm] = useState(InvoiceInitalValues);
const saveForm= (form) => {
data.invoiceLines=linedetails;
data.status="Submit";
const header = {
Auth_token: `${appUserConfig.accessTokenName}=${appUserConfig.accessToken}`,
User_name: appUserConfig.userName,
};
httpPost(SAVE_INVOICE,data, header)
.then((response) => {
if (response.status === 200) {
data.status="Draft";
toast.success('Successfully Saved', {position: toast.POSITION.TOP_RIGHT})
}
setForm({...form}); // i tried to set initial values using this code.
})
.catch((e) => {
console.log("e:", e);
toast.error('Error', {position: toast.POSITION.TOP_RIGHT})
});
}
i tried to set initial values after form save using
setForm({...form});
but its not working. can u help me to fix this
Upvotes: 0
Views: 272
Reputation: 306
I am not sure if I have got your question correctly but what it seems to me is you're trying to reset the values once the form is registered.
Which you can do by assigning the same values you did before when useState was initialized.
setForm(InvoiceInitalValues)
Upvotes: 1