diff --git a/README.md b/README.md index 3d6baee5..9107ade8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ - [TypeBox](#typebox) - [ArkType](#arktype) - [Valibot](#valibot) + - [effect-ts](#effect-ts) - [Backers](#backers) - [Sponsors](#sponsors) - [Contributors](#contributors) @@ -576,6 +577,57 @@ const App = () => { }; ``` +### [effect-ts](https://github.com/Effect-TS/effect) + +A powerful TypeScript framework that provides a fully-fledged functional effect system with a rich standard library. + +[![npm](https://img.shields.io/bundlephobia/minzip/effect?style=for-the-badge)] + +```typescript jsx +import React from 'react'; +import { useForm } from 'react-hook-form'; +import { effectTsResolver } from '@hookform/resolvers/effect-ts'; +import { Schema } from '@effect/schema'; + +const schema = Schema.Struct({ + username: Schema.String.pipe( + Schema.nonEmpty({ message: () => 'username required' }), + ), + password: Schema.String.pipe( + Schema.nonEmpty({ message: () => 'password required' }), + ), +}); + +type FormData = Schema.Schema.Type; + +interface Props { + onSubmit: (data: FormData) => void; +} + +function TestComponent({ onSubmit }: Props) { + const { + register, + handleSubmit, + formState: { errors }, + // provide generic if TS has issues inferring types + } = useForm({ + resolver: effectTsResolver(schema), + }); + + return ( +
+ + {errors.username && {errors.username.message}} + + + {errors.password && {errors.password.message}} + + +
+ ); +} +``` + ## Backers Thanks goes to all our backers! [[Become a backer](https://opencollective.com/react-hook-form#backer)]. diff --git a/effect-ts/src/types.ts b/effect-ts/src/types.ts index 7f44e1c7..875d32f9 100644 --- a/effect-ts/src/types.ts +++ b/effect-ts/src/types.ts @@ -2,11 +2,11 @@ import { Schema } from '@effect/schema'; import { ParseOptions } from '@effect/schema/AST'; import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form'; -export type Resolver = ( +export type Resolver = ( schema: Schema.Schema, config?: ParseOptions, ) => ( values: FieldValues, - context: TContext | undefined, + _context: TContext | undefined, options: ResolverOptions, ) => Promise>;