0.0.1 • Published 4 years ago
react-hook-form-resolvers v0.0.1
Goal
We are moving away from native support for Yup validation and begin to support others schema validation after React Hook Form v6.
Install
$ npm install react-hook-form-resolvers -D
Quickstart
import React from 'react';
import { useForm } from 'react-hook-form';
import { yup } from 'react-hook-form-resolvers';
const SignupSchema = yup.object().shape({
name: yup.string().required(),
age: yup.number().required(),
});
const App = () => {
const { register, handleSubmit } = useForm({
validationResolver: yup(SignupSchema), // yup, joi and even your own.
});
return (
<>
<form onSubmit={handleSubmit(d => console.log(d))}>
<label>Test</label>
<input name="test" ref={register} />
<input type="submit" />
</form>
</>
);
};
export default App;