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)
    ๐Ÿ‘Œ support remove([1,2,3])