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
useFieldArray doesn't remove correct indexes #4117
Comments
|
I'm having issues with remove using index too. It removes others than the clicked one |
hey @cargallo, please supply a codesandbox for me to reproduce the issue. |
Hi @bluebill1049 here is the sandbox. Click n times in append and then delete items, it always deletes the last one. https://codesandbox.io/s/react-hook-form-usefieldarray-forked-b0k18 |
Hi @cargallo it's made for field inputs: https://codesandbox.io/s/react-hook-form-usefieldarray-forked-qgx40 |
Hi, I realize that the problem in my code was that it mandatory to use item.id in the main wrapper of fields. If you set another key it doesn't work. Maybe you can throw an error in that case? Without putting the key in that way it was deleting the last one! https://codesandbox.io/s/react-hook-form-usefieldarray-forked-6urgq |
Describe the bug
I have discovered that after removing 5 indexes, wait for the render, then remove 5 other indexes, this time one of the index will be wrongly removed.
To Reproduce
On CSB: add all the possible attributes on the select field, then remove the two last ones. The first remove will be fine, on the second one, variants should be removed from index 9 to 17, but variant n°2 is removed, and variant n°9 is kept.
(Check console for id's and indexes)
Codesandbox link (Required)
https://codesandbox.io/s/problem-remove-usefieldarray-m8zub?file=/src/App.js
Expected behavior
Elements at indexes should be removed correctly.
Workaround
Using
remove
in a forEach instead of passing an array of indexes does the work.Desktop (please complete the following information):
Additional context
I'm making a form to add products variations, depending on attributes (Sizes, Colors, Cut, etc.), I discovered this bug when testing my migration from formik (it was triggering 30 renders per product variant update) to react-hook-form.
The text was updated successfully, but these errors were encountered: