MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / useFormField

Function useFormField

packages/react/src/components/form.tsx:41–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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