v7: config shouldUnregister
#4783
Replies: 5 comments 21 replies
-
We have Are you also intending on having all defaultValues loaded in the form values on render? That is something I've been trying to navigate around in v7. I think, should a field be set to |
Beta Was this translation helpful? Give feedback.
-
I think the proposal is valid. The only addition I would like to propose is adding back the global option. This option would be easier to use than having to write |
Beta Was this translation helpful? Give feedback.
-
Additionally, another idea to think about is we need to keep in my what is the best user experience/makes the most sense not it worked this way in V6, change it back so I don't need to refactor my code. If we do this, the library won't move forward. As most of the issues are focused around this and default values (I proposed this change in the RFC) my thoughts are:
shallow merge of default values: Most of the issues here are:
If this is a real deal-breaker, there is a feature request to add an option to remove the shallow merge. You can vote on it under the projects tab. |
Beta Was this translation helpful? Give feedback.
-
After upgrading from v6, this is a big issue. It would help a lot, having the shouldUnregister switch back: useForm({shouldUnregister: true}) |
Beta Was this translation helpful? Give feedback.
-
PR is merged, thanks for everyone's participation. |
Beta Was this translation helpful? Give feedback.
-
Context
In the first version of the hook form, we used to
unregister
inputs and remove their value & reference based on the component/input unmount. The initial design principle was trying to be closely aligned with the web standard and behavior. However, this yet to introduce confusion in the React community, and hence we introducedshouldUnregister
atuseForm
level, so inputs value can be retained despite been unmounted. In V7, we removed such config to reduce configuration and also reduce the complexity in the codebase. Unfortunately, this solution yet become the perfect solution and many users upvoted this feature request: #4355 so we are trying to find the middle grand to solve this problem by providing desired developer experience.Feature request
#4355
Proposal
Introduce
shouldUnreigster
We believe by having this config at the component/hook will eventually improve the developer experience in general, providing the option for developers to choose the right behavior for their application requirement.
useForm
level or hook/component level.useForm
level config takes precedence.Global level config
Component/Hook level config (can not overwrites global)
Note: Each one of them will invoke
unregister
atuseEffect
.PR (Draft)
#4758
let us know your thoughts, and we are looking forward to hearing your feedback.
Beta Was this translation helpful? Give feedback.
All reactions