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.

Input modifications are not persist in fields object from useFieldArray() hook

See original GitHub issue

This is quite a confusing thing but object fields exposed from the useFieldArray({name: 'test') hook is not equal to the current actual state (getValues(‘test’). And all modifications that has been made to this test array field using setValue() method are not exists in fields object. Somehow remove() method can temporary fix this bug, but this is even more strange.

If next appended row should copy edited value from the previous row this wouldn’t work as expected and old value will be copied.

Also useEffect wouldn’t be triggered during every row modification (except using exposed from the useFieldArray hook helper methods)

Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-usefieldarray-template-forked-gj10i?file=/src/index.js

Screenshots Screen Recording 2020-11-05 at 23 02 04

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
bluebill1049commented, Nov 6, 2020

Yeah, you right I’m a newbie to RHF. Maybe this is even better, because I can provide a feedback without deep context of this lib and describe what exactly I was confused of.

Nope, I disagree with the above and contradict the rest of your statement. If you not going to read the doc and complain about missing context, sorry I can’t help. I am not here to win you over an argument, by answering your issue, I am already here to help and it’s better than just simplify ignore your question.

I haven’t wound any information in useFieldArray section about the fields actual behavior and I think it should be mentioned that this object is not a reference to the real data (provided by getValues() method).

Complain is a very easy task to do 😃 You can contribute as this is open source, no one owns anyone a favor.

Also I was confused by an example with useEffect(() => {…}, [fields]) because I thought that fields declared as a dependency of an effect will behave like a real data.

context plz?

But why delete() temporarily fixes the situation - this is a good question that has to be clarified.

fix what? steps to reproduce?

1reaction
yekvercommented, Nov 6, 2020

Yeah, you right I’m a newbie to RHF. Maybe this is even better, because I can provide a feedback without deep context of this lib and describe what exactly I was confused of.

I haven’t found any information in useFieldArray section about the fields actual behavior and I think it should be mentioned that this object is not a reference to the real data (provided by getValues() method).

Also I was confused by an example with useEffect(() => {...}, [fields]) because I thought that fields declared as a dependency of an effect will behave like a real data. I had to read the source code to finally understand that fields changed only by hook helpers and nothing more. But why delete() temporarily fixes the situation - this is a good question that has to be clarified.

I think all of thinks should be carefully described in this docs section.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maintain state of useFieldArray react-hook-form - Stack Overflow
But when I click the previous button, the added fields disappear whereas data is still in localstorage. code for 2nd step: import {...
Read more >
useFieldArray - Simple React forms validation
Performant, flexible and extensible forms with easy-to-use validation.
Read more >
React-Hook-Form Library | Common Use Cases
For the form, I will provide a username, and password as input fields and city ... import { useForm } from "react-hook-form";export default...
Read more >
[Video] Using React Hook Form Field Array in a Modal Form
18:07 Going All in with React Hook Form for all input fields ▻ 21:45 Using Ionic React Components for styling ▻ 26:24 Deleting...
Read more >
Dynamic Forms with React Hook Form - Refine Dev
The defaultValue object properties will serve as our input field's default value. The mode property we're passing alongside the defaultValue ...
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