MCPcopy Create free account
hub / github.com/code100x/cms / useFormField

Function useFormField

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

Source from the content-addressed store, hash-verified

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

Callers 1

form.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected