MCPcopy Index your code
hub / github.com/code-with-antonio/nodebase / useFormField

Function useFormField

src/components/ui/form.tsx:45–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 4

FormLabelFunction · 0.85
FormControlFunction · 0.85
FormDescriptionFunction · 0.85
FormMessageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected