infoalloggi-monorepo/apps/infoalloggi/src/lib/zodForm.ts

18 lines
419 B
TypeScript
Raw Normal View History

2025-08-04 17:45:44 +02:00
import { zodResolver } from "@hookform/resolvers/zod";
import { type FieldValues, type UseFormProps, useForm } from "react-hook-form";
2025-08-04 17:45:44 +02:00
import type { z } from "zod";
export function useZodForm<
2025-08-28 18:27:07 +02:00
T extends z.ZodType<FieldValues, FieldValues>,
TContext,
>(
2025-08-28 18:27:07 +02:00
schema: T,
props?: Omit<UseFormProps<z.input<T>, TContext, z.output<T>>, "resolver">,
2025-08-04 17:45:44 +02:00
) {
2025-08-28 18:27:07 +02:00
return useForm({
resolver: zodResolver(schema),
...props,
});
2025-08-04 17:45:44 +02:00
}