Home

Awesome

Formik Validator Zod

Allows you to easily validate Formik forms with the power of Zod schemas.

WARNING: As of v2, this package uses native ESM and no longer provides a CommonJS export. If this is something you need, you should be able to use the dynamic import function or use v1 of this package.

Installation

This package is published both on NPM and JSR.

To install from NPM:

npm install formik-validator-zod

yarn add formik-validator-zod

bun add formik-validator-zod

To install from JSR:

npx jsr add @glazy/formik-validator-zod

yarn dlx jsr add @glazy/formik-validator-zod

bunx jsr add @glazy/formik-validator-zod

Example

import { Formik } from 'formik'
import { z } from 'zod'
import { withZodSchema } from 'formik-validator-zod'

const mySchema = z.object({
  email: z.string().email(),
  name: z.string(),
  age: z.number(),
})

const MyForm = () => {
  return (
    <Formik validate={withZodSchema(mySchema)} {...}>
      {...}
    </Formik>
  )
}