2025-08-04 17:45:44 +02:00
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
2025-08-07 14:50:40 +02:00
|
|
|
import { type FieldValues, type UseFormProps, useForm } from "react-hook-form";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-07 14:50:40 +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-07 14:50:40 +02:00
|
|
|
>(
|
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
|
|
|
}
|