remove doesnt work on useFieldArray when reset has been done on form
See original GitHub issueDescribe the bug Hello! I hope you are doing well!
The form does not remove the data but the UI elements are removed when using useFieldArray
after a reset
has been done on the form. If I provide the data as defaultValues
instead of the reset, when I remove an item, it works as intended.
To Reproduce Steps to reproduce the behavior:
- After the form has loaded, hit submit.
- You will see that there are 3 items in the array in the console log of the form data.
- Delete an item and hit submit again and you will see 3 items still in the array in the console.log.
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-cku66?file=/src/index.js
Expected behavior I expect when the UI changes, I hit remove on an element, after I hit submit it reflects what is actually on the form.
Additional context
Originally I thought the reset
was just like providing defaultValues
to the form but it seems to act completely different. reset
actually seems to register data differently with the form than using defaultValues
If I need to be more clear in my context let me know. Also, for some reason append and prepend do work, just not remove. Those only work after I call register after the reset.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Thanks! I like what you are doing! I look forward to seeing this project be successful!
oh shit, it didn’t save and it’s still on 6.0.5…
https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-uiigf?file=/src/index.js
one important line that i removed to get it working, useFieldArray doesn’t work with custom register which is register at useEffect.