Last active
October 16, 2024 15:15
-
-
Save danieljpgo/61e5973910c9e2df11a76f52b4869d10 to your computer and use it in GitHub Desktop.
react-hook-form + zod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
useForm as useHookForm, | |
UseFormProps as useHookFormProps, | |
} from "react-hook-form"; | |
import { zodResolver } from "@hookform/resolvers/zod"; | |
import { TypeOf, ZodSchema } from "zod"; | |
type UseFormProps<Z extends ZodSchema> = Omit< | |
useHookFormProps<TypeOf<Z>>, | |
'resolver' | |
> & { | |
schema: Z; | |
}; | |
export function useForm<Z extends ZodSchema>({ | |
schema, | |
...props | |
}: UseFormProps<Z>) { | |
return useHookForm({ ...props, resolver: zodResolver(schema) }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment