Set the value just before submission, but setValue("name", name)
wouldn't set the value on React Hook Form correctly... I've tried to use async
, but it still wouldn't work at all.
I tried to use the react hook form to save the data. However, setValue did not work.
const onSubmit = handleSubmit(
async (data) => {
await setValue("name", name)
// data.name is undefined
submitPost(data)
},
(err: any) => {
toast.error(err.message)
},
)
CodePudding user response:
Try this:
const onSubmit = (data) => {
let newdata = {
...data,
parameter_name: value_to_set
}
submitPost(newdata)
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>