1.3.0 • Published 2 months ago

zod-formik-adapter v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

zod-formik-adapter

codecov

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

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>
);
import { z } from 'zod';
import { Formik } from 'formik';
import { toFormikValidate } from 'zod-formik-adapter';

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

const Component = () => (
  <Formik
    validate={toFormikValidate(Schema)}
  >
    {...}
  </Formik>
);