-
Hi, guys! Version: Usage:
Problem: |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 21 replies
-
can you reproduce that in a CSB? |
Beta Was this translation helpful? Give feedback.
-
I know that this is an old discussion, but I recently encountered a similar challenge with v7 when attempting to use unregister. I eventually traced my issue to a util function being used by RHF, 'unset', which attempts to delete the key value from the default values object passed in when setting up the useForm hook. The issue arises when you are passing in an immutable object as your default values. In my case I was directly passing in an object from redux toolkit, which I believe uses immer. I was able to solve this issue by doing a shallow copy of the defaultValues object I pass into useForm. In case anyone runs into this in the future.... |
Beta Was this translation helpful? Give feedback.
-
The problem appears because of deep nesting. Creating |
Beta Was this translation helpful? Give feedback.
-
Variation of this scenario:
Essentially, it's possible to accidentally freeze the internal values state object used by react-hook-form by assigning the object reference in redux state. |
Beta Was this translation helpful? Give feedback.
-
I solve this by using reset method each time the component props changes |
Beta Was this translation helpful? Give feedback.
-
I had this issue and none of the above worked for, bear in mind I was using redux data to prepopulate the form using defaultValues. This is how my custom hook works correctly for simple values as well as for nested objects.
The ultimate change that made it work is moving the |
Beta Was this translation helpful? Give feedback.
-
Hello! I recently encountered this issue. I was using Immer to change a simple thing in my code: let values = getValues('academicInformation');
values = produce(values, (draft) => {
draft.forEach((item) => {
item.endDate = item.endDate
? new Date(item.endDate).toISOString().slice(0, 10)
: '';
});
}); Little did I know that Immer freezes values by default. There are two solutions:
|
Beta Was this translation helpful? Give feedback.
-
It's really a shitty issue! it made me rollback tons of changes |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 I'm getting this issue but for a different reason: when you pass in an async anonymous function for ![]() even a simple function like this will throw this error |
Beta Was this translation helpful? Give feedback.
The problem appears because of deep nesting.
Creating
deepCopy
of store object helped.