AppField doesn't exist on form object returned from useFormContext()
I've been trying to get this to work for two hours now. The premise sounds great but for some reason type inference isn't working.
I have my
form-context.ts
file:
Then my form.ts
file for exporting the useAppForm
hook:
Then the place where I want to create my form:
3 Replies
stormy-goldOP•2mo ago
So far so good, right? Everything's working. But then in my CommonSection.tsx when I try to access my form through useFormContext like this:
It's giving me:
Property 'AppField' does not exist on type 'ReactFormExtendedApi<Record<string, never>, any, any, any, any, any, any, any, any, any>'.ts(2339)
However, if I load my application all is working well. So for some reason my editor is telling me: this is not possible but in reality it's all working correctly.
Tried restarting editor, reloading everything it's just not accepting that AppField exists on the form.
The thing is, when I copy everything from CommonSection into the component where I use `useAppForm and access the form instance, it shows that AppField DOES exist on it.
Any idea what to do in order to fix thisforeign-sapphire•2mo ago
Two thoughts:
* The type is a bit iffy there. You create contexts before creating a form hook, so technically it is correct to assume that you do not have access to AppField. However, since calling your form component will be done by an App Form, it will have access to AppField. So that sounds like a type issue at the moment.
* This is for grouping multiple fields together to use for multiple forms, right? If so, there's a PR in the works to address field groups if you want to give that a spin and give feedback before it's released:
npm i https://pkg.pr.new/@tanstack/react-form@1469
stormy-goldOP•2mo ago
Thanks a lot will give it a whirl on Monday!