Input modifications are not persist in fields object from useFieldArray() hook
See original GitHub issueThis 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
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.
Complain is a very easy task to do 😃 You can contribute as this is open source, no one owns anyone a favor.
context plz?
fix what? steps to reproduce?
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 bygetValues()
method).Also I was confused by an example with
useEffect(() => {...}, [fields])
because I thought thatfields
declared as a dependency of aneffect
will behave like a real data. I had to read the source code to finally understand thatfields
changed only by hook helpers and nothing more. But whydelete()
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.