field array loses values using Controller
See original GitHub issueTo Reproduce Steps to reproduce the behavior:
- Go to https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-78qdb?file=/src/fieldArray.js:665-670
- Click “Append”, enter any text
- Click “hide” button and then “show”
- See default values in text input
If I use register instead of Controller everything is fine.
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-78qdb?file=/src/fieldArray.js:665-670
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Top Results From Across the Web
React-hook-form field value get lost when i collapse, add or ...
I am trying to add new panels from Add button click and remove panel from Remove button click, its working fine, problem is,...
Read more >useFieldArray - Simple React forms validation
Performant, flexible and extensible forms with easy-to-use validation.
Read more >10 Most Common Mistakes That PHP Developers Make - Toptal
After going through the first foreach loop, $array remains unchanged but, as explained above, $value is left as a dangling reference to the...
Read more >SANtricity 11.30 Maintaining a Storage Array Using CLI
The CLI command wrapper is a shell that identifies storage array controllers, embeds operational terminals, embeds script commands, and passes these values to ......
Read more >2080-UM002M-EN-E Micro830, Micro850, and Micro870 ...
Micro850 Controller Catalog Numbers 2080-LC50-24AWB, 2080-L50E-24AWB, ... you need to remove power from all field devices, you must include MCR.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I am going to roll back this fix guys, as this is breaking a deeply nested field #4941 https://github.com/react-hook-form/react-hook-form/issues/4941, so to work around this issue.
let me explain the problem because useFieldArray needs defaultValue as the initial input state. Toggling input doesn’t really change the defaultValue stored in useFieldArray resulted in the above issue.
https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-31soo
so work around this issue for toggling input, you can use getValues to set the defaultValue, well I know this is not convenient, but it’s about to cover all use cases, and I hope for your understanding. also you can use
useWatchAPI for the individual’s defaultValue as well.https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-ez7un?file=/src/fieldArray.js
I have also included a new section in the doc:
This is very unobvious 🙁 And I can’t find this information in documentation