Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ui/src/components/ui/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { cn } from "@/lib/utils"
import { Label } from "@/components/ui/label"

const Form = FormProvider
const FormRoot = FormProvider

type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
Expand Down Expand Up @@ -44,12 +44,16 @@ const useFormField = () => {
const itemContext = React.useContext(FormItemContext)
const { getFieldState, formState } = useFormContext()

const fieldState = getFieldState(fieldContext.name, formState)

if (!fieldContext) {
throw new Error("useFormField should be used within <FormField>")
}

if (!itemContext) {
throw new Error("useFormField should be used within <FormItem>")
}

const fieldState = React.useMemo(() => getFieldState(fieldContext.name, formState), [fieldContext.name, formState])

const { id } = itemContext

return {
Expand Down Expand Up @@ -166,7 +170,7 @@ FormMessage.displayName = "FormMessage"

export {
useFormField,
Form,
FormRoot as Form,
FormItem,
FormLabel,
FormControl,
Expand Down