2
Watch
17
Star
1
Fork
1
Issue

An adapter of zod object validation to Formik validation schema

robertLichtnow
robertLichtnow
pushedAt 3 weeks ago

robertLichtnow/zod-formik-adapter

zod-formik-adapter

This library adapts a zod schema to work as a validationSchema prop on Formik

IMPORTANT: Currently, this library does not work with zod union. See more here.

Install

# npm
$ npm install zod-formik-adapter

# yarn
$ yarn add zod-formik-adapter

Usage

import { z } from 'zod';
import { Formik } from 'formik';
import { toFormikValidationSchema } from 'zod-formik-adapter';

const Schema = z.object({
  name: z.string(),
  age: z.number(),
});

const Component = () => (
  <Formik
    validationSchema={toFormikValidationSchema(Schema)}
  >
    {...}
  </Formik>
);
ucloud ads