R
fn

useFormContext

v0.0.16testeddemo

Retrieve the {@link 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 = any, TOutput = TInput>(): UseFormReturn<TInput, TOutput> | null{ ... }

Type Parameters

TInputextends object= any
TOutput= TInput

Returns

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