Skip to Content
Prism UI
Integrations

Zod Adapter

createZodResolver, the complete public API of @prismrepo/adapter-zod.

@prismrepo/adapter-zod is a thin Zod validation integration, compatible with @hookform/resolvers/zod. It does not depend on @prismrepo/adapter-rhf, and never imports react-hook-form at runtime (only its types), see Package Responsibilities.

createZodResolver

function createZodResolver<TSchema extends ZodType<unknown, Record<string, unknown>>>(
  schema: TSchema,
): Resolver<SchemaInput<TSchema>, unknown, SchemaOutput<TSchema>>;

Adapts a Zod schema into the resolver shape usePrismForm's options.resolver accepts (React Hook Form's own UseFormProps.resolver), using @hookform/resolvers/zod to do the actual translation. This is the entire adapter, no schema validation or error formatting is reimplemented. The returned resolver's input/output types are inferred from schema itself (a z.infer-equivalent), not a generic parameter you write by hand.

const schema = z.object({ email: z.string().email('Enter a valid email') });

const form = usePrismForm(definition, {
  resolver: createZodResolver(schema),
});

Zod 4 is required

createZodResolver's TSchema constraint is built against Zod 4's two-parameter ZodType<Output, Input> shape. A real Zod 3 schema's three-parameter ZodType<Output, Def, Input> shape does not satisfy it, confirmed directly against a real Zod 3 schema, not assumed. If your project is still on Zod 3, upgrade before adopting this adapter.

react-hook-form is declared as a type-only peer dependency of this package, an import type only, never a runtime import, required because the resolver's return type is RHF's own Resolver type. See Package Responsibilities for why this doesn't create a runtime coupling to @prismrepo/adapter-rhf.

What the resolver actually validates against

Whatever usePrismForm's FormDefinition was built with (createFormBuilder(registry).defineForm<TValues>) determines the form's value shape; createZodResolver(schema)'s schema should describe that same shape. A failed validation surfaces through each field's normal field.error, there's no separate Zod-specific error channel, see Default Values and Validation.

On this page