How to extend the useForm hook? #1434
Unanswered
DoubleDebug
asked this question in
Q&A
Replies: 1 comment 2 replies
-
The generic parameters are for the validation. The
|
Beta Was this translation helpful? Give feedback.
2 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, I'm new to the
@tanstack/react-form
library and I need help with customizing theuseForm
hook.What exactly do I want?
Let's say I have a Zod schema for each of my forms:
Instead of writing this:
... I want to write this:
... and get the same result.
Why do I want this?
I have tens of forms in my application and I want to reduce boilerplate as much as possible. I also want to have some "global" control over the
useForm
hook in case I want to change the behavior for ALL forms in my application. This is why I decided to make a wrapper for theuseForm
hook.To be clear, I don't want to reuse a part of my
FormOptions
(as suggested here). I want to slightly modify how theuseForm
behaves across my entire app.What I tried
There are 2 problems with my implementation.
FormOptions
is a generic type and it requires 10 type arguments. 🤯This means that it doesn't work and it doesn't correctly inherit the
Person
type.Am I going in the wrong direction?
I read in the docs that
This is partly the reason why I'm making this discussion. Is there a smarter way to do this?
Beta Was this translation helpful? Give feedback.
All reactions