react-hook-form v4.9.1 Release Notes
Release Date: 2020-02-09 // about 4 years ago-
๐ฑ ๐ฎ 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)
๐ supportremove([1,2,3])