issue: formState is incorrect after submission - fix is an ugly hack #11088
-
Version Number7.43.9 Codesandbox/Expo snackhttps://codesandbox.io/s/shy-tree-lsl6wt Steps to reproduceScenario: Submit to the server errors out Look at Before {isSubmitting: false, isSubmitted: false, isSubmitSuccessful: false} After {isSubmitting: false, isSubmitted: true, isSubmitSuccessful: true} Side Note: This bug is a major cause of concern as seen in this related discussion: https://github.com/orgs/react-hook-form/discussions/10103#discussioncomment-5927542 Expected behaviourThe form state MUST reflect What browsers are you seeing the problem on?Firefox, Chrome Relevant log outputNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
If you look at the source code of how the This means that you can set a server ( function Form() {
const { handleSubmit, setError, formState } = useForm()
const onSubmit = () => {
try {
throw new Error("internal server error")
} catch (error) {
setError("root.server", {
type: "server",
message: error.message,
})
}
}
const { isSubmitSuccessful } = formState // <== the isSubmitSuccessful state stays false on submit failure
return <form onSubmit={handleSubmit(onSubmit, onInvalid)}>...</form>
} |
Beta Was this translation helpful? Give feedback.
-
As other people have pointed out before, this is a breaking change from some versions ago - I used it in a previous project and got blindsided in a new one when my tests suddenly didn't work. So, is this gonna be reverted to the previous (and, in my opinion, more consistent) behaviour, or should we expect this to be the default behaviour from now on? Some months have gone by already, and from previous comments reverting this should be easy, in case that is the chosen route. |
Beta Was this translation helpful? Give feedback.
-
This has been fixed in See v7.50.0 release notes, or specifically this PR |
Beta Was this translation helpful? Give feedback.
I've done an MR to at least have a consistent isSubmitting state without changing current behavior :
#11214
Because for now any error result in an infinite isSubmitting state, that's totally counter intuitive