Replies: 2 comments 1 reply
-
@bluebill1049 what do you think? |
Beta Was this translation helpful? Give feedback.
1 reply
-
I've created an issue to make it possible reference it in other issues or PRs #13009 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello 👋
While working on the Lenses project, I’ve encountered several challenges that would benefit from improvements in the core
react-hook-form
library.1. Allow Control to Accept Generic Value Types
Currently, the
Control
type requires both a value type and a path. This presents a problem when we don't have a specific path, which is often the case when working with generic or path-agnostic components.Problem
We’d like to support simple usage like:
But
Control<T, Path>
requires a valid path type—so passingstring
orarray
causes type errors. To work around this, we created a shim:How the Shim Works
HookFormControlShim
is a helper type that wraps the actual type you want to work with in a known structure.__DO_NOT_USE_HOOK_FORM_CONTROL_SHIM__
is a constant string literal used as a dummy path. It always matches the single known key inside the shim object.Here’s a simplified version:
This allows us to "trick" the type system into accepting any generic type by wrapping it in a known object shape with a fixed path key. Then, immediately, we unwrap it when passing the path to the form methods.
Suggestion
Allow the
Control<T>
type to accept arbitrary generic types without constraints and requiring a validPath<T>
up front. This would eliminate the need forHookFormControlShim
and enable straightforward usage in path-agnostic code.2. Support Transformed Controllers
Lenses uses a
reflect
method that can remap or restructure values, requiring transformations during value access and update.Currently:
Suggestion
Introduce a native transformation API like:
This would return a new
Control
instance with automatic remapping on read/write3. Make
useController
anduseWatch
Reactive to Name ChangesHooks like
useController
anduseWatch
don’t currently respond to changes in thename
parameter.In Lenses, reusable components are designed to dynamically bind to different paths—so having static
name
tracking makes this difficult.Suggestion
Enable
useController
anduseWatch
to reactively respond to changes in thename
prop to support dynamic bindings.4. Subscribe to Unregistered Fields
Lenses implements internal caching, which makes it important to track when a field is unregistered.
Currently, I use a manual workaround to detect field unregistration
Beta Was this translation helpful? Give feedback.
All reactions