🎮 feature/support custom schema validation (#974)
import React from "react";
import { useForm } from "react-hook-form";
import Joi from "@hapi/joi";
const validationSchema = Joi.object({
username: Joi.string().required()
});
const resolver = (data: any, validationContext) => {
const { error, value: values } = validationSchema.validate(data, {
abortEarly: false
});
return {
values: error ? {} : values,
errors: error
? error.details.reduce((previous, currentError) => {
return {
...previous,
[currentError.path[0]]: currentError
};
}, {})
: {}
};
};
export default function App() {
const { register, handleSubmit, errors } = useForm({
validationResolver: resolver,
validationContext: { test: "test" }
});
return (
<form onSubmit={handleSubmit(d => console.log(d))}>
<input type="text" name="username" ref={register} />
<input type="submit" />
</form>
);
}
🐞 close #954 fix type for ErrorMessage component props (#966)
🐞 fix #967 issue around getValues with defaultValues (#968)
🐞 fix #969 fields compare function
✌️ close #951 include keyName prop for custom id (#957)
✌🏻 improve type keyName for useFieldArray (#983)
👨🏻💻 improve type for ref (#990)
💉 fix #988 isValid form state with useFieldArray schema (#991)
⛏ fix #994 prevent useFieldArray items unregister (#995)
⌨️ useFieldArray remove method support array of indexes (#980)
support remove([1,2,3])