react-hook-form icon indicating copy to clipboard operation
react-hook-form copied to clipboard

issue: useFieldArray cut off null values from array and cause broken indexing next entities

Open dzwiedziu-nkg opened this issue 7 months ago • 1 comments

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

dzwiedziu-nkg avatar Jul 04 '24 18:07 dzwiedziu-nkg