Replies: 2 comments 1 reply
-
Also having this issue! |
Beta Was this translation helpful? Give feedback.
-
I faced a similar issue, but from a slightly different perspective. I was using useFieldArray, and part of my rendered values (specifically const { fields } = useFieldArray({ control, name: 'someSpecificForm' })) were tied to inputs managed separately via useState. When I called reset(), the input that wasn't tied to react-hook-form was also unexpectedly reset to its initial value. After some investigation, I realized that reset() causes useFieldArray's mySuperField to unmount and remount components. This unmounting affects all child components, including those managed by useState, which explains why my input's state reverted to its initial value (null in my case) after the remount. I hope this helps others facing similar issues! small code snippet:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
After I submit my form, I call
form.reset(valuesFromApi)
to set the new values as my defaultValues, and be able to set my dirty state, this works as expected. However, this is causing all my components that useuseFieldArray
to remount completely, which causes the internal keys of the items to be recalculated, and all the children to unmount and remount as well, which causes lost focus in input fields etc.I have an autosave which runs every couple of seconds, which is why this loss of focus is such an issue for me. I'm currently working around it by disabling autosave when the user has focus in an input or textarea, but it doesn't feel correct having this, and quite fragile. Eg file inputs also suffer from this, and won't set the value properly if the item has remounted in the meantime.
I've used
shouldUnregister: false
, which doesn't fix my issue.Beta Was this translation helpful? Give feedback.
All reactions