Insert/Append/Prepend drops nested data
See original GitHub issueI 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:
- Go to CSB
- Click on buttons:
APPEND
,APPEND NESTED
,PREPEND
,INSERT
,PREPEND NESTED
- Click on
SUBMIT
- Scroll down to console, and check the output data
- Only element fields created by
setValue
will preservefield1
; element fields that are created byappend
,insert
,prepend
do not havefield1
.
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:
- Created 2 years ago
- Reactions:1
- Comments:12 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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()
anduseWatch()
, 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.@bluebill1049 I can reproduce my code. I want something like that. https://codesandbox.io/s/priceless-dijkstra-4j4vv?file=/src/App.tsx