Glazy / formik-validator-zod

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

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

License:MIT License


Languages

Language:TypeScript 95.3%Language:Shell 4.7%