react-hook-form: setValue not working for arrays with controller
Describe the bug I wonder if this bug is related to https://github.com/react-hook-form/react-hook-form/issues/5232 as the issues I usually see are related to non-primitive values, namely arrays.
To Reproduce
- Use controller interface instead of register to track fields in your form
- Add a manually tracked field via
defaultValues - Add a callback modifying the manual field and call it (in my example by pressing the “Remove” button)
- Press the “submit” button
Codesandbox link (Required) https://codesandbox.io/s/dark-voice-glnie?file=/src/App.tsx
Expected behavior The submitted values are
{
"array": ["a"],
"firstName": "alll"
}
Actual behavior The submitted values are
{
"array": ["a", "b"],
"firstName": "alll"
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (3 by maintainers)
@damianobarbati Are you able to upgrade
react-selectto version4.0.0or newer? Doing so fixes the issues you mention above. Can you verify if that would also resolve the other issues you’re seeing?@mrlubos I see it working properly with the latest
react-select. I’ll ping if I manage to reproduce the real app behaviour, thank you!If you share a CodeSandbox we might be able to help you @damianobarbati
@damianobarbati As of version
7.8.8, I define the form like this.And in the same component I also add this hook.
Hopefully this helps!
Thanks @bluebill1049, I’ll have a look. Doing this triggers the other bug I reported in #5232 but I have not been able to reproduce it in CodeSandbox so far. Will keep you posted if I succeed