You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all,
I usually like to provide type information only once in a project. Since we're using Zod for schemas, we can also infer types from it. Which means, once provided a schema to RHF, it has all the information it needs.
Which makes this fully typed:
import{useForm}from'@/lib/hooks/use-form/zod'constschema=z.object({email: z.string().min(1,{message: 'email is required'}),password: z.string().min(5,{message: 'password requires at least 5 characters'}),})const{
register,
handleSubmit,formState: { errors },}=useForm({ schema })
Implementation of the Zod specific useForm swaps the resolver and uses z.infer<...>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I usually like to provide type information only once in a project. Since we're using Zod for schemas, we can also infer types from it. Which means, once provided a schema to RHF, it has all the information it needs.
Which makes this fully typed:
Implementation of the Zod specific
useForm
swaps the resolver and usesz.infer<...>
I was thinking this can be a cool addition to the resolvers repo, and a better developer experience. Maybe something like
Beta Was this translation helpful? Give feedback.
All reactions