useFieldArray keep value when appending after removing
See original GitHub issueDescribe the bug
In my defaultValues
, I have an array of values that I want to render using useFieldArray
. It render correctly, but when I remove the last item and append a new item (calling append
without arguments), it renders with the value from defaultValue.
To Reproduce Steps to reproduce the behavior:
- Go to https://codesandbox.io/s/react-hook-form-usefieldarray-template-e7x5l
- Click on
delete
button from the second line - Click on
append
button - The controlled component get value from
defaultValues
Additional context Not sure if it’s a bug or intentional
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
UsefieldArray react hook form deleting the last element only
Basically I'm trying to append and delete but the problem is when I'm deleting its deleting only the last element. append is working...
Read more >useFieldArray - Simple React forms validation
In case of validation error, the root property is appended to formState.errors? ... solution: the remove action is happened after the second render...
Read more >Effective forms: building dynamic array fields with useFieldArray
Using append to push values to the array; Getting the current value of any field with watch and useWatch; Applying remove to remove...
Read more >Form - Atom Learning
Dynamic fields - useFieldArray() · fields : fields is an object keeping all the dynamic fields stored in the field array. · append...
Read more >Creating recursive and dynamic forms with React Hook Form ...
Using the useFieldArray hook. In our form, we have the friends array. In our case, we want users to be able to add,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh, ok. So it’s not a bug. Thanks for fast reply!
I’m having the same issue. I believe it might be similar to https://github.com/react-hook-form/react-hook-form/issues/7935
Apologies, I don’t have time to make a codesandbox yet. But I am using useFieldArray. It works with
register
, but not<Controller />
.