Zod overrides react-hook-form validation

I have the following form scheme. When I specify rules={{required: true}} on the field it doesn't work because of zod validation scheme.
const trendyolFormScheme = z.object({
  brand: z.string().optional(),
  attributes: z.array(
    z
      .object({
        attributeId: z.number(),
        customAttributeValue: z.string().optional(),
        attributeValueId: z.number().optional(),
      })
      .optional(),
  ),
});


I want to be able to override Zod or being able to make field required based on api response (later on).
Solution
And as you mentioned you can make it required based on api response, you can use a discriminated union to make things required depending on some data from the api https://zod.dev/?id=discriminated-unions
Was this page helpful?