-
|
Hello! The best approach I found is this one: export type TForm = ReturnType<typeof useAppForm<any, any, any, any, any, any, any, any, any, any, any, any>>;
export interface FormContextProps<T extends TForm = TForm> {
form: T;
formMode: FormMode; // My custom attribute stored in the context
}
const FormContext = createContext<FormContextProps<TForm> | undefined>(undefined);
export function FormContextProvider<T extends TForm>({
form,
formMode,
children,
}: PropsWithChildren<FormContextProps<T>>) {
return (
<FormContext value={{ 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 export default function App() {
const { form } = useSampleForm();
return (
<>
<h1>Simple Form Example</h1>
<SampleForm form={form} />
</>
);
}I tried using 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.
Replies: 1 comment
-
|
I have found another way of creating the context which does not have this issue, see #2145 (comment) |
Beta Was this translation helpful? Give feedback.
I have found another way of creating the context which does not have this issue, see #2145 (comment)