question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

remove doesnt work on useFieldArray when reset has been done on form

See original GitHub issue

Describe 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:

  1. After the form has loaded, hit submit.
  2. You will see that there are 3 items in the array in the console log of the form data.
  3. 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
poeticninjacommented, Jul 16, 2020

Thanks! I like what you are doing! I look forward to seeing this project be successful!

1reaction
bluebill1049commented, Jul 16, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

remove from useFieldArray doesn't work correctly · Issue #1571
use useFieldArray; Append new members; remove ing doesn't work as expected, ... I have a form for creating an array of floors like...
Read more >
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
Performant, flexible and extensible forms with easy-to-use validation.
Read more >
React Hook Form - useFieldArray - Remove ERROR
A custom hook for working with Field Arrays (dynamic inputs). 0. 77.
Read more >
Effective forms: building dynamic array fields with useFieldArray
This was the final article of the React Hook Form series. ... As a result of the changes to be made, we have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found