-
-
Notifications
You must be signed in to change notification settings - Fork 449
feat(react-form): Add withFormLens
#1469
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
base: main
Are you sure you want to change the base?
Conversation
View your CI Pipeline Execution ↗ for commit c9ed053.
☁️ Nx Cloud last updated this comment at |
Issues that could be addressed:
This has now been addressed. If onSubmitMeta is unset, any value will do. If it is set, you must match it exactly. |
While the previous separate implementation was compatible with AppForm, users wouldn't have been able to use any field/form components in the render itself. This commit allows them to do that, at the expense of not being compatible with useForm.
The unit tests should be reusable in case this isn't the desired approach. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1469 +/- ##
==========================================
+ Coverage 89.13% 90.01% +0.88%
==========================================
Files 31 32 +1
Lines 1417 1542 +125
Branches 362 371 +9
==========================================
+ Hits 1263 1388 +125
Misses 137 137
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Related PR: #1334 |
Something to consider:
|
This type will help with a lens API for forms so that only names leading to the subset data are allowed.
#1475 sounded like an interesting idea, so I'll try to tinker with that and come up with unit tests. The note at the top of the PR still applies. |
…k-form into form-group-api
Strange, the derived state from the form lens isn't updating ... Issue: React input unfocuses when changing input. Unsure why. |
this is because useMemo is not intended for stable objects see https://react.dev/reference/react/useMemo for more info
It's because it forwards the form's Field component. I would much rather not mess with that as the lens should not have separate API as much as possible, especially on the React side of things. |
withFormLens
This is not confirmed to be added. This is an opportunity to get feedback on this suggestion and/or implementation.
Todos
- [ ] Is this concept okay to begin with?It's more related to discussion than an actual Todo.This PR implements a variation of
withForm
that can be used to create form groups. This form group allows extendingdefaultValues
and has no expectations of form level validators.This distinguishes it both from
withForm
as well as instantiations of forms.Here's an extract of the documentation:
Reusing groups of fields in multiple forms
Sometimes, a pair of fields are so closely related that it makes sense to group and reuse them — like the password example listed in the linked fields guide. Instead of repeating this logic across multiple forms, you can utilize the
withFormLens
higher-order component.Rewriting the passwords example using
withFormLens
would look like this:We can now use these grouped fields in any form that implements the default values:
I have not contacted maintainers about this implementation. This may go against desired features or philosophies of the form, and I would like to hear input on that. You are free to commit to this branch.