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.

V6: useFieldArray with nested useFieldArray renders with fields [empty]

See original GitHub issue

Describe the bug I experience that when I add an entry to a field array with a nested field array and remove it again. Then I get 2 renders of my outer field array. One with [] (length 0) and afterwards one with [empty] (length 1). Then my application crashes since it can’t get the id of undefined.

This is the data I can see with the React Components DevTools:

image

The issue only exists in v6. Not in v7.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-xif3x
  2. Click on append
  3. Click on delete
  4. Click on submit
  5. Click on append
  6. See that it crashes

Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-xif3x

Expected behavior The field array does not contain empty values.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bluebill1049commented, Apr 22, 2021

patched again with latest v6.

1reaction
bimbeonguyencommented, Apr 21, 2021

Hello @bluebill1049, this bug is still existing. Step to reproduce: Append -> Append -> Append -> Delete first, second item => the fields return [object, empty] Append -> Append -> Append -> Delete first, second and third item => the fields return [empty, empty, epmty]

https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-xif3x

Read more comments on GitHub >

github_iconTop Results From Across the Web

useFieldArray - Simple React forms validation
useFieldArray automatically generates a unique identifier named id which is ... for nested field array, you will have to cast the field array...
Read more >
A brand new website interface for an even better experience!
V6 : useFieldArray with nested useFieldArray renders with fields [empty]
Read more >
React hook forms with nested fields array from an async ...
First is that the nested is tasks not challenges // UserTaskFields.js // ... const { fields, remove } = useFieldArray({ control, ...
Read more >
V6 - React Hook Form - building dynamic form (Field Array)
In this video tutorial, we are going to through how to build a dynamic form with useFieldArray and useWatch.
Read more >
nested react hook form | The AI Search Engine You Control
Code: https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-9sxrt?file=/src/fieldArray.js:302-1778. <ul> {fields.map((item, ...
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