Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hannoeru/formik-effect-schema

effect schema utils for Formik
https://github.com/hannoeru/formik-effect-schema

Last synced: 11 days ago
JSON representation

effect schema utils for Formik

Awesome Lists containing this project

README

        

# formik-effect-schema

[![NPM version](https://img.shields.io/npm/v/formik-effect-schema?color=a1b858&label=)](https://www.npmjs.com/package/formik-effect-schema)

This library adapts a [@effect/schema](https://github.com/Effect-TS/effect/tree/main/packages/schema) schema to work as a `validationSchema` prop or `validate` prop on [Formik](https://formik.org/)

## Install

```sh
# npm
$ npm install formik-effect-schema

# yarn
$ yarn add formik-effect-schema

# pnpm
$ pnpm add formik-effect-schema
```

## Usage

```TSX
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

const Component = () => (

validationSchema={toValidationSchema(formSchema)}
>
{/** ... */}

);
```

```TSX
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

const Component = () => (

validate={toValidate(formSchema)}
>
{/** ... */}

);
```

## License

[MIT](./LICENSE) License © 2024 [hannoeru](https://github.com/hannoeru)