useFieldArray and Controller - unexpected results #13290
-
|
Hi, I've been doing some investigation into useFieldArray, and I am bumping into some interesting problems. Please see this CodeSandbox: https://codesandbox.io/p/sandbox/rpwdrj The code here is fairly straightforward. Click 'Append Item' to append to the 'array' object. Type some text into the input fields and click 'Submit edit'. However:
I am following the react-hook-form examples, and I cannot figure out why these 2 behave differently. They are setup differently ( Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
This is all working as I would expect. I think the confusion arises because you have two separate forms and it's hard to keep track of what input is bound to what form. I've made a new CodeSandbox that includes full types and does not perform any destructuring of the form methods. For your example, The
type Form1Data = {
array: {
firstName: string;
}[];
};It doesn't have a |
Beta Was this translation helpful? Give feedback.
This is all working as I would expect. I think the confusion arises because you have two separate forms and it's hard to keep track of what input is bound to what form. I've made a new CodeSandbox that includes full types and does not perform any destructuring of the form methods.
For your example,
registerandControllerbehave differently because they are bound to different forms. Theregisterinput is updating the editable sub-form. When you type in the input, the main form is not altered until you click submit. Here,registercomes fromform2(the edit form).The
Controllerinput is bound to the main form. When you type in that input, the<Display />component will update immediately.…