MCPcopy Create free account
hub / github.com/better-auth/examples / useFormField

Function useFormField

nuxt-example/components/ui/form/useFormField.ts:11–36  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import { FORM_ITEM_INJECTION_KEY } from "./injectionKeys";
10
11export function useFormField() {
12 const fieldContext = inject(FieldContextKey);
13 const fieldItemContext = inject(FORM_ITEM_INJECTION_KEY);
14
15 if (!fieldContext)
16 throw new Error("useFormField should be used within <FormField>");
17
18 const { name } = fieldContext;
19 const id = fieldItemContext;
20
21 const fieldState = {
22 valid: useIsFieldValid(name),
23 isDirty: useIsFieldDirty(name),
24 isTouched: useIsFieldTouched(name),
25 error: useFieldError(name),
26 };
27
28 return {
29 id,
30 name,
31 formItemId: `${id}-form-item`,
32 formDescriptionId: `${id}-form-item-description`,
33 formMessageId: `${id}-form-item-message`,
34 ...fieldState,
35 };
36}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected