zod form

https://github.com/juliusmarminge/t3-complete/blob/main/src/utils/zod-form.ts

Here is hook made by julius. With new zod I get error:

import { zodResolver } from "@hookform/resolvers/zod";
import { useForm, type UseFormProps } from "react-hook-form";
import { type ZodType } from "zod";

export function useZodForm<TSchema extends ZodType>(
  props: Omit<UseFormProps<TSchema["_input"]>, "resolver"> & {
    schema: TSchema;
  },
) {
  const form = useForm<TSchema["_input"]>({
    ...props,
    resolver: zodResolver(props.schema, undefined),
  });

  return form;
}

Argument of type 'TSchema' is not assignable to parameter of type 'ZodType<any, any, any>'.
  Type 'ZodType<any, ZodTypeDef, any>' is not assignable to type 'ZodType<any, any, any>'.
    The types of 'refine(...)._def.typeName' are incompatible between these types.
image.png
Was this page helpful?