MCPcopy
hub / github.com/vantezzen/autoform / useFormField

Function useFormField

packages/shadcn/src/components/ui/form.tsx:44–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42}
43
44const useFormField = () => {
45 const fieldContext = React.useContext(FormFieldContext)
46 const itemContext = React.useContext(FormItemContext)
47 const { getFieldState, formState } = useFormContext()
48
49 const fieldState = getFieldState(fieldContext.name, formState)
50
51 if (!fieldContext) {
52 throw new Error("useFormField should be used within <FormField>")
53 }
54
55 const { id } = itemContext
56
57 return {
58 id,
59 name: fieldContext.name,
60 formItemId: `${id}-form-item`,
61 formDescriptionId: `${id}-form-item-description`,
62 formMessageId: `${id}-form-item-message`,
63 ...fieldState,
64 }
65}
66
67type FormItemContextValue = {
68 id: string

Callers 1

form.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected