I posted this question on react-hook-form issues but thought of posting here too in case anyone found a solution for it.
I'm having this problem with isValid state when using react-hook-form on a stepper. The state of isValid seems a bit messed up when we use a back button. For example, if first step is valid and you go on to the next, trigger an error and go back, isValid will be false even though the first step is still valid.
This is a problem because I would like to use isValid as the state for the 'next' button to be disabled or not.
Is there any suggestions how to get this working or is it a bug?
Or is there another suggestion for what variable to use to disable the button?
Steps to reproduce
Expected behaviour
isValid should match the valid state of current step
React hook form version: 6.14.0 but also seen on 7.33.0
EDIT: For anyone having the same problem.. someone answered my question on react-hook -form's discussion page.
<input
type="hidden"
{...register("step1", {
shouldUnregister: true
})}
/>
This makes the isValid state somehow refresh when going backwards and forwards in the stepper.
CSB with this solution, see different step components: https://codesandbox.io/s/jovial-swartz-t31nu3?file=/src/steps/Step1.js:299-419
Github discussion: https://github.com/react-hook-form/react-hook-form/discussions/8787
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With