React Hook Form: Values reset when navigating steps (multi-step form) #13386
Replies: 3 comments 3 replies
-
|
One thing in the posted code is expected: useEffect(() => {
if (method === "ONLINE") {
form.setValue("venue", "");
}
if (method === "PHYSICAL") {
form.setValue("platform", undefined);
}
}, [method, form]);With the default For async function handleNext() {
console.log("before", form.getValues());
const isValid = await form.trigger(steps[currentStep].fields);
console.log("after trigger", form.getValues());
if (isValid && !isLastStep) {
setCurrentStep((prev) => prev + 1);
queueMicrotask(() => console.log("after step", form.getValues()));
}
}If the values disappear only after the step changes, replace one custom field with a plain registered input temporarily: <input {...form.register("title")} />If the plain input keeps its value, the issue is in the custom field wiring. If it also resets, check whether the whole |
Beta Was this translation helpful? Give feedback.
-
|
@zixuanng8368-sudo I would suggest you to try this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building a multi-step form using:
React Hook Form
Zod
Next.js (App Router)
Each step conditionally renders different fields using a switch(currentStep) pattern.
When I click Next to move to another step:
the isValid is set to true and allow me to move to the next step
but the previously filled values (e.g. title, shortDescription, platform) become undefined
form.watch() confirms the values are actually lost, not just UI
I would like to ask what might be the problem here
(The form is not finished yet)
Beta Was this translation helpful? Give feedback.
All reactions