Home / Function/ useFormField() — ui Function Reference

useFormField() — ui Function Reference

Architecture documentation for the useFormField() function in form.tsx from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  29e41b07_d0cf_4866_9a61_54195767eeb1["useFormField()"]
  7d8d565b_677a_b1ee_05eb_401ffef201c2["form.tsx"]
  29e41b07_d0cf_4866_9a61_54195767eeb1 -->|defined in| 7d8d565b_677a_b1ee_05eb_401ffef201c2
  c89810f0_cc19_4415_96b9_5ecab8dea8bf["FormLabel()"]
  c89810f0_cc19_4415_96b9_5ecab8dea8bf -->|calls| 29e41b07_d0cf_4866_9a61_54195767eeb1
  a50c345e_da7e_33fa_e9d6_bef21a9cc473["FormControl()"]
  a50c345e_da7e_33fa_e9d6_bef21a9cc473 -->|calls| 29e41b07_d0cf_4866_9a61_54195767eeb1
  c3394ed6_f519_57c2_4f36_025eb2a82ba0["FormDescription()"]
  c3394ed6_f519_57c2_4f36_025eb2a82ba0 -->|calls| 29e41b07_d0cf_4866_9a61_54195767eeb1
  146a8ec3_8ec0_8bb6_695a_94e4c457569d["FormMessage()"]
  146a8ec3_8ec0_8bb6_695a_94e4c457569d -->|calls| 29e41b07_d0cf_4866_9a61_54195767eeb1
  style 29e41b07_d0cf_4866_9a61_54195767eeb1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

deprecated/www/registry/default/ui/form.tsx lines 42–67

const useFormField = () => {
  const fieldContext = React.useContext(FormFieldContext)
  const itemContext = React.useContext(FormItemContext)
  const { getFieldState, formState } = useFormContext()

  if (!fieldContext) {
    throw new Error("useFormField should be used within <FormField>")
  }

  if (!itemContext) {
    throw new Error("useFormField should be used within <FormItem>")
  }

  const fieldState = getFieldState(fieldContext.name, formState)

  const { id } = itemContext

  return {
    id,
    name: fieldContext.name,
    formItemId: `${id}-form-item`,
    formDescriptionId: `${id}-form-item-description`,
    formMessageId: `${id}-form-item-message`,
    ...fieldState,
  }
}

Subdomains

Frequently Asked Questions

What does useFormField() do?
useFormField() is a function in the ui codebase, defined in deprecated/www/registry/default/ui/form.tsx.
Where is useFormField() defined?
useFormField() is defined in deprecated/www/registry/default/ui/form.tsx at line 42.
What calls useFormField()?
useFormField() is called by 4 function(s): FormControl, FormDescription, FormLabel, FormMessage.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free