Skip to content

hannoeru/formik-effect-schema

Repository files navigation

formik-effect-schema

NPM version

This library adapts a @effect/schema schema to work as a validationSchema prop or validate prop on Formik

Install

# npm
$ npm install formik-effect-schema

# yarn
$ yarn add formik-effect-schema

# pnpm
$ pnpm add formik-effect-schema

Usage

import { Schema as S } from '@effect/schema'
import { Formik } from 'formik';
import { toValidationSchema } from 'formik-effect-schema';

const formSchema = S.Struct({
  name: S.String,
  age: S.Number,
})

type Values = S.Schema.Type<typeof formSchema>

const Component = () => (
  <Formik<Values>
    validationSchema={toValidationSchema(formSchema)}
  >
    {/** ... */}
  </Formik>
);
import { Schema as S } from '@effect/schema'
import { Formik } from 'formik';
import { toValidate } from 'formik-effect-schema';

const formSchema = S.Struct({
  name: S.String,
  age: S.Number,
})

type Values = S.Schema.Type<typeof formSchema>

const Component = () => (
  <Formik<Values>
    validate={toValidate(formSchema)}
  >
    {/** ... */}
  </Formik>
);

License

MIT License © 2024 hannoeru