Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If I remove all the items of a list using useFieldArray, I don't get an empty array, I get an array with null items. #5506

Closed
giomv opened this issue Jun 6, 2021 · 2 comments · May be fixed by hamzahsn/GitCard#102, hamzahsn/GitCard#116, hamzahsn/GitCard#118 or hamzahsn/GitCard#119
Labels

Comments

@giomv
Copy link

giomv commented Jun 6, 2021

Describe the bug
I have a nested array with 3 parent elements and I child element, using useFieldArray. If I remove all the default items I get an array with 3 null elements instead of an empty array, using watch. When I try to add a new element, I get 4 parent elements, 3 of them are the elements previously deleted.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/react-hook-form-usefieldarray-forked-iw71g?file=/src/index.js
  2. Click on Remove on each of the 3 items.
  3. See the watch elements and instead of an empty array you see null elements inside the array.
  4. Click on Add
  5. You see 4 elements instead of one.

Codesandbox link (Required)
https://codesandbox.io/s/react-hook-form-usefieldarray-forked-iw71g?file=/src/index.js

Expected behavior
I expect first to have an empty array in the watch when I remove all the elements. And after adding one element on that empty array, I should have only one element in the form and the watch.

Screenshots

Captura de Pantalla 2021-06-06 a la(s) 17 47 25

Captura de Pantalla 2021-06-06 a la(s) 17 47 30

Captura de Pantalla 2021-06-06 a la(s) 17 47 34

Captura de Pantalla 2021-06-06 a la(s) 17 47 38

Captura de Pantalla 2021-06-06 a la(s) 17 47 44

Desktop (please complete the following information):Captura de Pantalla 2021-06-06 a la(s) 17 47 25

  • OS: MacOS
  • Browser: Chrome
  • Version: latest

Additional context
React Hook Form version: 6.15.7

@bluebill1049 bluebill1049 added status: under investigation aware of this issue and pending for investigation V6 and removed status: under investigation aware of this issue and pending for investigation labels Jun 6, 2021
@giomv
Copy link
Author

giomv commented Jun 10, 2021

It's working great in the new version. Thank you very much!

@bluebill1049
Copy link
Member

It's working great in the new version. Thank you very much!

Welcome. thanks for the detailed issue report too.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.