watch/useWatch/getValues issue with conditionally rendered fields
See original GitHub issueDescribe the bug
After hiding and showing conditional fields their watch
e getValues
values are not retrieved on render. Values are available after some specific actions, like button clicks, though. This issue occur even with shouldUnregister
option set false
.
To Reproduce Steps to reproduce the behavior:
- input some value on conditionally rendered fields (User name)
- toggle off these fields
- toggle them on again
- check messages on page (“User name is on watch” and “User name is on getValues”) or check logs. Messages won’t be rendered and
username
prop won’t show on logs
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-v6-getvalues-jvmw6?file=/src/index.jsx:1004-1119
Expected behavior
It is expected that username
’s value should be restored and returned by watch
and getValues
on toggle on user name field
Desktop (please complete the following information): OS: Windows 10 Pro 1909 Browser: Brave Version: 1.10.97
Additional context Please, let me know if I missed something and this is not a bug, so I can move to Discussions.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Yes, this was what I ended up doing.
Changed to latest version and it works correctly.
Thank you guys for your very quick replies and awesome work. Sorry for my mistake.
the simplest way just toggle the visibility of that input.
that’s what i am seeing here (unless i am missing steps), can you change to latest patch instead of RC version?