React hook form with zod resolver optional field

Viewed 18

I want to make a form with React-hook-form and zod resolver where all fields are optional but fields still required despite making them optional in zod schema:

const schema = z.object({
    name: z.string().min(3).max(50).optional(),
    description: z.string().min(3).max(255).optional(),
    image: clientImageSchema.optional(),
  })
const {...} = useForm({ resolver: zodResolver(schema) }) 

when submitting the form with blank inputs it validates fields as required. Where is the error or the mistake ?

0 Answers
Related