Update values in useFieldArray from outside form
See original GitHub issueHi,
I’m not sure if I’m doing something wrong, or that I’ve found a bug.
Within my project I’m using a useFieldArray which contains categories. I can insert a category from a modal. This works fine. But when I try to update the value of this category nothing happens when I use setValue, or the fields are removed when I reset the values baesd on getValues() because the categories aren’t an array yet, but save as categories[0].title: "test".
You can find my simplified use case over here: https://codesandbox.io/s/old-glitter-wffzq
Only works for one value now because I’d hardcode the index in handleUpdate
How to update a value correctly from outside the form? Thanks in advance for your help!
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (10 by maintainers)
Top Results From Across the Web
useFieldArray - Simple React forms validation
Update input/inputs at a particular position, updated fields will get unmount and remount. If this is not desired behavior, please use setValue API...
Read more >Updating default values of a React-Hook-Form, does not ...
The problem is that when the state updates, form default values are updated, but the method useFieldArray attribute fields are not updated ...
Read more >Effective forms: building dynamic array fields with useFieldArray
update – updates input/inputs at a particular position; replace – replaces the total field array values; remove – removes input/inputs at a particular...
Read more >React Hook Form - useFieldArray - YouTube
In this session, we are taking a look at the useFieldArray custom hook to manage your dynamic form fields.working example: ...
Read more >React Hook Form - useFieldArray - Get Current Values
React Hook Form - useFieldArray - Get Current Values. 0. Embed Fork Create Sandbox Sign in. Sandbox Info. React Hook Form - useFieldArray...
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 Free
Top 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

@bluebill1049 No worries about being a but later. We’re all human haha 😃
Taken from your example;
You can see the input value being updated, but the logs and the “test” behind the the input still showing the old value.
My use case is that I add a category of
useFieldArrayfrom within a modal. Then the category title isn’t shown in an input, but as title of a block.So the red circle is the title from the
useFieldArray, but to actually save the value (and the order) within theuseFieldArrayI use a hidden input. I use hidden inputs because I have to send the values to my backendSo my code looks like:
The green circle opens a modal to edit the title value which is prefilled within the modal. When I save the edit modal the
handleUpdatefrom the codesandbox is triggered. But as seen in both codesandbox examples thefield.titleisn’t updated correctly.Hope you understand my use case and issue now 😃
thank you @rnnyrk it’s just a bit easier for me to take a look tonight.