Skip to main content

Helper to simplify validating Formik values with Zod

Works with
This package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
3 months ago

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>
  )
}

Add Package

deno add @glazy/formik-validator-zod

Import symbol

import * as mod from "@glazy/formik-validator-zod";

Add Package

npx jsr add @glazy/formik-validator-zod

Import symbol

import * as mod from "@glazy/formik-validator-zod";

Add Package

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

Import symbol

import * as mod from "@glazy/formik-validator-zod";

Add Package

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

Import symbol

import * as mod from "@glazy/formik-validator-zod";

Add Package

bunx jsr add @glazy/formik-validator-zod

Import symbol

import * as mod from "@glazy/formik-validator-zod";