Values are out of sync when a field disabled attribute depends of another field value #11735
Unanswered
olivierpascal
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Workaround: React.useEffect(() => {
const subscription = watch(() =>
setTimeout(() => console.log('values:', getValues()), 0)
);
return () => subscription.unsubscribe();
}, [watch, getValues]); |
Beta Was this translation helpful? Give feedback.
0 replies
-
Could you please explain why this is not a bug, and what is the recommended way to deal with it? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Version Number
7.51.2
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/muddy-sky-kcshvj?file=%2Fsrc%2FApp.tsx
Steps to reproduce
Go to https://codesandbox.io/p/sandbox/muddy-sky-kcshvj?file=%2Fsrc%2FApp.tsx
Check "Enabled", which will enable "First Name"
values:
{ "isEnabled": true } // OK
values:
{ "isEnabled": true, "firstName": "Bob" } // OK
values:
{ "isEnabled": false, "firstName": "Bob" } // NOT OK
expected values:
{ "isEnabled": false }
values:
{ "isEnabled": true } // NOT OK
expected values:
{ "isEnabled": true, "firstName": "Bob" }
isEnabled
andfirstName
are out of sync.Expected behaviour
You may argue that this is the expected behavior because
watch
can't predict what I will do next, onceisEnabled
is checked.I will argue that since the
disabled
attribute change the value, it should trigger awatch
update.What browsers are you seeing the problem on?
Firefox, Chrome, Safari, Edge
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions