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.

isDirty is true for objects inside fieldArray elements before changes

See original GitHub issue

Describe the bug When using useFieldArray with an array of objects, containing nested objects, dirtyFields will be true for the nested object as soon as it is added, before any of its children have been changed.

To Reproduce Steps to reproduce the behavior:

  1. Go to the below Codesandbox
  2. No fields are currently dirty (as shown in the screenshot below)
  3. Click ‘Add User’
  4. Dirty fields is now:
[
  {
    "details": true // Expected: false
  }
]
  1. Fill out either (or both) of the inputs
  2. Dirty fields is now (if both filled out):
[
  {
    "details": {
      "first": true,
      "last": true
    }
  }
]

Codesandbox link (Required) https://codesandbox.io/s/infallible-wave-kg5z4?file=/src/App.js

V7.6.7

Expected behavior I would expect either of the following:

  • details to be false - as I have not modified any of its child fields yet
  • details to be { first: false, last: false } - as it should know about the child fields already as they have been registered

Screenshots image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 90

Additional context N/A

Issue Analytics

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

github_iconTop GitHub Comments

0reactions
bluebill1049commented, May 27, 2021

Is it worth sticking that in the docs with a brief explanation? Maybe it will help someone else?

definitely a good idea. I will get that updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

issue: Form isDirty doesn't always match dirtyFields #7970
Issue 1. At this point, you'll see the overall form isDirty = false and dirtyFields has true values within it.
Read more >
react-hook-form isDirty seems weird for me - Stack Overflow
I expect isDirty should be true only when value of input element changes. Is that normal in react-hook-form? // I had to make...
Read more >
Initializing From State - Redux Form
To keep dirty form values when it reinitializes, you can set keepDirtyOnReinitialize to true. By default, reinitializing the form replaces all dirty values ......
Read more >
Form - Ant Design
High performance Form component with data scope management. Including data collection, verification, and styles.
Read more >
FormArray - Angular
It accepts an array that matches the structure of the control, and does its best to match the values to the correct controls...
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