-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[useForm]: eliminate tech debt #2668
Comments
I have a small request for improvements. While using lens, I've faced the need to access data within |
@Kuznietsov Do you have an example? |
You can provide For validation we also pass parent data to the This is what you are looking for or you have another cases? |
Thanks for the quick response. Example:Records in a table may be linked, and specific rules declare these relations. When the value is changed, there is a need to update the record's fields so as not to break the rules of relations or shift dates if the relation type is changed. I've achieved this goal with Maybe, something like: small.onChange((prev, current) => {
const relatedRecord = this.big().prop(current.relatedId).get();
....
return updatedSmall;
}); |
To Do
Remove state from the ref approach
Previously, we used refs to avoid closures inside hooks and to memoize the form API, ensuring that API callbacks were not recreated on every state change. This was necessary to prevent breaking user components wrapped in
React.memo
that rely on form API methods. We can consider migrating to native state with setState callbacks to always have access to the latest value without needing to include form values in hook dependencies. However, we first need to address the issue of closures in theLenses
implementation.Enable storing form state outside the
useForm
hookAdd
value
andonValueChange
props to allow external control of the form state. When these props are provided, the form should operate based on them, similar to theuseFormState
hook.Lens improvements:
Resolve closure limitations:
The current
Lens
implementation creates lenses only on mount, providing getters tied to the initial state:If we move away from the ref-based approach, this will prevent accessing updated values outside closures.
Memoize lenses:
Ensure lenses are memoized to prevent breaking components that receive lenses as props and are wrapped in
React.memo
.See #2683
The text was updated successfully, but these errors were encountered: