fn

useFormContext

v0.0.14testeddemo

Retrieve the useForm instance provided by an ancestor, for building field components that live anywhere in the form's subtree. Returns null when no form has been provided (so callers can support standalone use).

Example

ts
// Inside a custom <TextField> rendered within a useForm() component:
const form = useFormContext();
if (form)
  form.setFieldValue('email', 'a@b.com');

Demo

Loading demo…

Signature

ts
export function useFormContext<TInput extends object = Record<string, unknown>, TOutput = TInput>(): UseFormReturn<TInput, TOutput> | null{ ... }

Type Parameters

TInputextends object= Record<string, unknown>
TOutput= TInput

Returns

UseFormReturn<TInput, TOutput> | nullThe injected form instance, or null