📋 Validation resolvers: Yup, Zod, AJV, Joi, Superstruct, Vest, class-validator, io-ts, typanion, Ajv, TypeBox, Valibot and nope.
MIT License
Bot releases are visible (Hide)
Published by github-actions[bot] over 1 year ago
You don't need to explicitly provide the type when using the useForm function because it automatically infers the types from the Yup schema.
Before
const schema = Yup.shape({ name: string });
const { register } = useForm<{name: string}>({ resolver: yupResolver(schema) });
After
const schema = Yup.shape({ name: string });
const { register } = useForm({ resolver: yupResolver(schema) });
Published by github-actions[bot] over 1 year ago
rawValues
option to raw
Before:
schemaOptions?: ValidatorOptions,
After:
schemaOptions?: {
validator?: ValidatorOptions;
transformer?: ClassTransformOptions;
}
import { useForm } from 'react-hook-form';
import { typeboxResolver } from '@hookform/resolvers/typebox';
import { Type } from '@sinclair/typebox';
const schema = Type.Object({
username: Type.String({ minLength: 1 }),
password: Type.String({ minLength: 1 }),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: typeboxResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};