How to type `form` ?
1. Parent component
2. Fetch data from useQuery
3. need
form prop when use withForm
AppFieldExtendedReactFormApi is not available to import
9 Replies
equal-aqua•2mo ago
Form Composition | TanStack Form React Docs
A common criticism of TanStack Form is its verbosity out-of-the-box. While this can be useful for educational purposes helping enforce understanding our APIs it's not ideal in production use cases. As...
dependent-tan•2mo ago
if you mean how to align
withForm's expected type with your own, you should have a formOptions constant with shared data.
That data includes:
* defaultValues
* validatorscriminal-purpleOP•2mo ago
should I spread
formOpts
dependent-tan•2mo ago
yes
criminal-purpleOP•2mo ago
What i mean is should i wrap withForm in both
Filters and Filter?
Is this the right pattern?
because I used to do <FormProvider /> and useFormContext() in RHFdependent-tan•2mo ago
sort of looks alright. I assume with
ChildComponent you meant Filter, and with the handleSubmit call right after setting the value
One thing I can recommend:
handleChange and setValue both do the same thing internally, but handleChange is clearer with its intentcriminal-purpleOP•2mo ago
OH nice! Haven't thought of that.
I still think something similiar to this is neccessary. Sometimes, people got deeply nested form field. If you have to warp all of them with an HOC, we're going back to prop drilling issue.
dependent-tan•2mo ago
well, my honest opinion is that prop drilling is the only type safe way to go about it.
However, you're right. There's also cases where you literally cannot pass it as prop (certain table layouts, routing files), so that's where a
useTypedFormContext would come in handy
it's not a big deal to implement, so perhaps after the array PR is done, I can quickly implement thatcriminal-purpleOP•2mo ago
I get your point.