react-hook-form: getValues('fieldArray') doesn't seem to work inside of event handler
Describe the bug
When using useFieldArray, getValues('fieldArray') returns undefined inside of an event handler. But getValues().fieldArray returns the array though. 😅
To Reproduce Steps to reproduce the behavior:
- Click on ‘Append’.
- See log in the console.
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-usefieldarray-template-forked-erbwu?file=/src/index.js:1575-1702
Expected behavior
getValues('fieldArray') should returns the same thing as getValues().fieldArray.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (9 by maintainers)
I will take a look this useWatch inconsistency tmr.
Sure! 😃 Would be glad to try to reconstruct this on CSB. I’ll work on it sometime this week~
sorry to hear that 🙏
fieldArray.lengthis the right one, let me explain what’s happening, with uncontrolled input, those form value states live inside the inptus, which the reason why you needwatch('fieldArray', fields), this goes to the same as watch need a defaultValue, otherwise it will returnundefinedwhen you try to watch input, because the input is not even rendered yet.Ahh okay, didn’t know that it was expected. Thanks, as always, Bill! 😃)