"use client"; "use client"; import * as React from "react"; import { FormProvider, useForm } from "react-hook-form"; import { Button } from "@/components/ui/button"; export type BaseFormProps> = { defaultValues?: Partial; onSubmit: (values: T) => Promise | void; children?: React.ReactNode; submitLabel?: string; }; export default function BaseForm>({ defaultValues, onSubmit, children, submitLabel = "Save", }: BaseFormProps) { const methods = useForm({ defaultValues: defaultValues as any }); // If parent provides new defaultValues (e.g. after an async fetch), reset the form React.useEffect(() => { if (defaultValues) { methods.reset(defaultValues as any); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [JSON.stringify(defaultValues)]); return (
{ await onSubmit(v as T); })} className="space-y-4" > {children}
); }