react-hook-form / core

Framework agnostic hook form core lib
https://react-hook-form.com/
MIT License
124 stars 1 forks source link

development of hookform/core for alternative frameworks #4

Open ap0nia opened 2 weeks ago

ap0nia commented 2 weeks ago

Is your feature request related to a problem? Please describe.

I'd like a Svelte implementation of react-hook-form. I'd like to expose corresponding register hooks that can automatically bind an input element to a store and automatically track changes while optimizing updates.

Describe the solution you'd like

There's an existing implementation of a framework agnostic core library that I'd like to extend. I'd like to use it to build out a proof of concept for Svelte.

I've implemented a version of @hookform/core from the ground up with vanilla JS in mind. Using this core, I built @hookform/react and passed all of the related tests from react-hook-form. My work can be found here: https://github.com/ap0nia/forms.js/tree/main/packages/react

Describe alternatives you've considered

I'm not a big fan of existing solutions for Svelte because it's either type-unsafe or heavily relies on two-way data binding, which is too opaque for my needs.

Additional context

This issue is forwarded from an issue I made at the core library because I'm not sure how visible it is there.

I think a possible point of difficult is divergence of the hookform/core library and its dependents from the main react-hook-form library, since I wrote everything from scratch to emulate the same external behavior, but not necessarily the internals. I'm willing handle the maintenance burden if it enables hookform to be applicable more widely.

I was just really interested in hearing thoughts about this topic, thanks!

bluebill1049 commented 2 weeks ago

hi @ap0nia thanks for the feature request, let me get this one out first: https://github.com/react-hook-form/react-hook-form/pull/11522 then we can refine the core

ap0nia commented 2 weeks ago

Thanks, I really love the DX of react-hook-form and I wanted to plug-in the logic into other frameworks. Let me know when it's appropriate for me to contribute to the core, and the best way to go about it.

From the top of my head, an example RFC I could open is a registerElement method which is the equivalent of the ref property returned by the register function. It would provide a vanilla JS way to register an HTMLElement into the form control's logic.