issue: unregister does not work correctly when conditionally rendering fields with the same key #11736
Unanswered
archiemcquaid
asked this question in
Q&A
Replies: 1 comment
-
https://react-hook-form.com/faqs#Whyisdefaultvaluenotchangingcorrectlywithternaryoperator |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Version Number
7.51.1
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/eloquent-lake-y6pm3d
Steps to reproduce
Hi. I have an issue where values from unregistered fields persist if another field is registered with the same key afterwards.
name="province"
.test
in the Province inputunregister
is called. A state select is rendered with the samename="province"
onSubmit
is called with{country: 'US', province: 'test'}
Interestingly when logging the result of
watch()
it showsprovince
is correctly removed however when clickingonSubmit
, the old value returns.Expected behaviour
name="province"
.test
in the Province inputunregister
is called. A state select is rendered with the samename="province"
province
is unset and no state has been selected.What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions