-
With Zod it is possible to give a description to a schema, for example: const mySchema = z.object({
name: z.string().describe('The name of the thing')
});
type MyType = z.infer<typeof mySchema>; When using the zod resolver, is it possible to access and display this information? For example: const {
register,
handleSubmit,
formState: { errors, descriptions },
} = useForm<MyType>({
resolver: zodResolver(mySchema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register("name")} />
<p>{descriptions.name}</p>
{errors.name?.message && <p>{errors.name?.message}</p>}
</form>
); Note that |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
No, there is no support to get description from zod schema via react-hook-form but you extract zod schema into a separated module then import it everywhere you need to access schema field. For example:
|
Beta Was this translation helpful? Give feedback.
-
It seems like the generated instance via .and method, havs no property named "shape". say const schemaC = A.and(B) schemaC.shape (X) |
Beta Was this translation helpful? Give feedback.
@devklick
No, there is no support to get description from zod schema via react-hook-form but you extract zod schema into a separated module then import it everywhere you need to access schema field.
For example: