You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using React Hook Form to render two form fields. One field uses useFieldArray(), and the other is a normal field. I have a use case where I need to fetch the initial data for the form from an API. I am using form.reset() for setting the default value
For the normal field, the initial value is an array. I am rendering a multi-select component in the actual project where the items from the array are the values the user selected earlier. Upon adding a field to the useFieldArray component, the isDirty state for the second field is changing.
I am attaching the CodeSandbox link for the above case. You can check this by opening the dev tools and adding a new field in the field array (phone number field), which will change the isDirty state of the test field to true.
Can someone explain what I am doing wrong here? Why does the isDirty state of the test field change when I try to add a field in the phone number field?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am using React Hook Form to render two form fields. One field uses useFieldArray(), and the other is a normal field. I have a use case where I need to fetch the initial data for the form from an API. I am using form.reset() for setting the default value
For the normal field, the initial value is an array. I am rendering a multi-select component in the actual project where the items from the array are the values the user selected earlier. Upon adding a field to the useFieldArray component, the isDirty state for the second field is changing.
I am attaching the CodeSandbox link for the above case. You can check this by opening the dev tools and adding a new field in the field array (phone number field), which will change the isDirty state of the test field to true.
Can someone explain what I am doing wrong here? Why does the isDirty state of the test field change when I try to add a field in the phone number field?
Beta Was this translation helpful? Give feedback.
All reactions