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.

Insert/Append/Prepend drops nested data

See original GitHub issue

I will like to thank you for building such great library, it literally saved me from perf hell.

Describe the bug Using useFieldArray’s append, insert, prepend with nested array of objects, where one of the value in the object is another nested array. The field (field1 in the example) gets omitted.

    insert(1, {
      name: "insert",
      nestedArray: [{ field1: ["field1", "field11"], field2: "field2" }]
    });

will generate the following form data.

{
  "test": [
      {
          "name": "insert",
          "nestedArray": [
              {
                  "field2": "field2"
              }
          ]
      }
  ]
}

To Reproduce Steps to reproduce the behavior:

  1. Go to CSB
  2. Click on buttons: APPEND, APPEND NESTED, PREPEND, INSERT, PREPEND NESTED
  3. Click on SUBMIT
  4. Scroll down to console, and check the output data
  5. Only element fields created by setValue will preserve field1; element fields that are created by append, insert, prepend do not have field1.

Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-forked-nw7pz?file=/src/fieldArray.js

Expected behavior append, insert, prepend should preserve deeply nested array (field1).

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: 91

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Xadoycommented, Jun 15, 2021

Thanks for being so responsive, I have changed my data structure to work around this. Also thanks for the knowledge, I am not sure if I am using RHF the worst way (maybe “anti-patter”), but I have been thru I lots of problems, especially for setValues() and useWatch(), they always triggered some unexpected behaviour to me. I might try to summarize those cases if I could. Or I should read a little more about how to use RHF properly.

0reactions
dancixxcommented, Jul 8, 2021

@bluebill1049 I can reproduce my code. I want something like that. https://codesandbox.io/s/priceless-dijkstra-4j4vv?file=/src/App.tsx

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: Append JSON objects to nested list - Stack Overflow
I'm trying to iterate through a list of IP addresses, and extracting the JSON data from my url, ...
Read more >
Append/Prepend to a nested attribute - Couchbase Forums
Hello,. You are doing the correct thing, by extracting the document, parsing it and add the new JSON attribute to the JSON attribute...
Read more >
Append - Wolfram Language Documentation
Append [expr, elem] gives expr with elem appended. Append[elem] represents an operator form of Append that can be applied to an expression.
Read more >
Apply functions with purrr : : CHEAT SHEET - GitLab
length(x)) Add to end of list. append(x, list(d = 1)) prepend(x, values, before = ... Use a two step process to create a...
Read more >
Inserts with APPEND Hint. - Ask TOM
what it says is: .... During direct-path INSERT operations, Oracle appends the inserted data after existing data in the table. Data is written ......
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