react-hook-form
react-hook-form copied to clipboard
issue: useFieldArray cut off null values from array and cause broken indexing next entities
Version Number
7.52.1
Codesandbox/Expo snack
https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-6jn6cm?file=/src/index.js
Steps to reproduce
I add null values to array in defaultValues. useFieldArray cut off null values from array. So indexing of is invalid. We get only two array elements with broken index.
Its happen because you wrap by compact function in this: https://github.com/react-hook-form/react-hook-form/blob/ee7b5883d029e084e433fdd873cac21dfff4a11e/src/logic/createFormControl.ts#L539
Expected behaviour
When you change react-hook-form version to 7.12.2 in packages.json this example works good. We get all array elements with correct index.
What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
I agree if it's marked as a duplicate of #12053. The cause of the error is the same. The example is different because I am using complex nested fields instead of an array of strings.
would you like to send a PR with this?
I can create PR if no one else is working on this
I can create PR if no one else is working on this
Yes, please would be great to attach some tests with it as well.
but why we have null in the default values? field array doesn't support flat array.
Does not support flat field array.
https://react-hook-form.com/docs/usefieldarray
field array doesn't support flat array.
Why?