You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello!
I am trying to set up a custom context to wrap my forms in order to store state in an efficient way and have the ability of reading custom variables in my custom form fields.
The best approach I found is this one:
exporttypeTForm=ReturnType<typeofuseAppForm<any,any,any,any,any,any,any,any,any,any,any,any>>;exportinterfaceFormContextProps<TextendsTForm=TForm>{form: T;formMode: FormMode;// My custom attribute stored in the context}constFormContext=createContext<FormContextProps<TForm>|undefined>(undefined);exportfunctionFormContextProvider<TextendsTForm>({
form,
formMode,
children,}: PropsWithChildren<FormContextProps<T>>){return(<FormContextvalue={{ form, formMode }}><form.AppForm>{children}</form.AppForm></FormContext>);}
Edit: I found that the type error occurs only if the form has a field which may be a JS File object 😵💫 Opening issue #2145
It causes the following type error when the form instance is passed to the context:
exportdefaultfunctionApp(){const{ form }=useSampleForm();return(<><h1>SimpleFormExample</h1><SampleFormform={form}/></>);}
src/index.tsx(30,19): error TS2322: Type 'AppFieldExtendedReactFormApi<{ firstName: string; formMode: FormMode; formFile: File | null; }, FormValidateOrFn<{ firstName: string; formMode: FormMode; formFile: File | null; }> | undefined, ... 11 more ..., {}>' is not assignable to type 'AppFieldExtendedReactFormApi<any, any, any, any, any, any, any, any, any, any, any, any, { readonly TextInput: ({ ...props }: DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>) => Element; }, {}>'.
Types of property 'pushFieldValue' are incompatible.
Type '<TField extends never>(field: TField, value: (TField extends "formMode" | "firstName" | "formFile" | "formFile.text" | `formFile.text.${string}` | "formFile.name" | "formFile.size" | "formFile.type" | ... 9 more ... | `formFile.stream.${string}` ? DeepRecord<...>[TField] : never) extends any[] ? (any[] & (TField ext...' is not assignable to type '<TField extends never>(field: TField, value: any, options?: UpdateMetaOptions | undefined) => void'.
Types of parameters 'value' and 'value' are incompatible.
Type 'any' is not assignable to type 'never'.
I tried using AnyFormApi without success. Shall a new type of Any... be added to the library? Or maybe is there a better way of doing this? Thanks in advance ❤️
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I am trying to set up a custom context to wrap my forms in order to store state in an efficient way and have the ability of reading custom variables in my custom form fields.
The best approach I found is this one:
Edit: I found that the type error occurs only if the form has a field which may be a JS
Fileobject 😵💫 Opening issue #2145It causes the following type error when the form instance is passed to the context:
I tried using
AnyFormApiwithout success. Shall a new type ofAny...be added to the library? Or maybe is there a better way of doing this? Thanks in advance ❤️Link to the stackblitz sandbox: https://stackblitz.com/edit/tanstack-form-zz8oewgu
I guess this is related to #1921
Beta Was this translation helpful? Give feedback.
All reactions