issue: React Hook Form : validation error object is empty during first submit #10820
-
Version Number7.45.4 Codesandbox/Expo snackhttps://codesandbox.io/p/sandbox/relaxed-sun-gc35yk Steps to reproduceIt's working perfectly fine in codesandbox. but not in my local machine I've tried in chrome, edge browser. and I'm getting this output. Screenshot : https://photos.app.goo.gl/UxZ2zmk86fubmQAZA The Expected behaviourboth errors object should be same even in first submit. What browsers are you seeing the problem on?Chrome, Edge Relevant log outputNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Do you destruct the const { errors } = formState ...as opposed to formState.errors |
Beta Was this translation helpful? Give feedback.
-
@Moshyfawn yes, I destructured |
Beta Was this translation helpful? Give feedback.
-
I'm not sure yet. This seems to be related to a re-render problem, and the typical cause for the value to say behind like this is often due to incorrect value subscription, i.e. the value wasn't read before use. |
Beta Was this translation helpful? Give feedback.
-
OK, I've not looked at the The state's being updated at the end of the The I think it's going to be one of those "API design limitation". @bluebill1049, correct me of I'm wrong. |
Beta Was this translation helpful? Give feedback.
-
@Moshyfawn, seems like you are correct. Thank you so much for looking into the source code. |
Beta Was this translation helpful? Give feedback.
-
thanks @Moshyfawn yes that's right. |
Beta Was this translation helpful? Give feedback.
OK, I've not looked at the
handleSubmit
source code in a while 🤦The state's being updated at the end of the
handleSubmit
execution, so you won't getformState
update until after the submission process has ended.The
formState
is going to be up to date at the time of the next component render due to the excision order.I think it's going to be one of those "API design limitation". @bluebill1049, correct me of I'm wrong.