TanStackT
TanStack3mo ago
9 replies
dangerous-fuchsia

Error with useForm : Type instantiation is excessively deep and possibly infinite

Hy everyone, i have a error with useForm when i want to make a form and definite in a context the error throw : Type instantiation is excessively deep and possibly infinite.

Do you say how to resolve the error and where she come ?

Code :

Form Context
import React, { PropsWithChildren } from 'react';
import { createFormHook, createFormHookContexts, FormApi } from '@tanstack/react-form';
export const { fieldContext, formContext, useFieldContext } = createFormHookContexts();
export type AppFormType<TValues> = FormApi<
  TValues,
  any,
  any,
  any,
  any,
  any,
  any,
  any,
  any,
  any,
  any
>;

export const { useAppForm } = createFormHook({
  fieldContext,
  formContext,
  fieldComponents: {},
  formComponents: {},
});

type FormProviderProps<T> = PropsWithChildren<{
  defaultValues: T;
}>;

export function GlobalFormProvider<T>({ defaultValues, children }: FormProviderProps<T>) {
  const form = useAppForm({ defaultValues });

  return <formContext.Provider value={form}>{children}</formContext.Provider>;
}
Was this page helpful?