npm react-hook-form 7.42.0
Version 7.42.0

latest releases: 7.53.1, 7.53.0, 7.52.2...
22 months ago

📽 feature: validate function to include formValues (#9079)

type FormValues = {
  number1: number;
  number2: number;
};

// Making exported validate function isolated for validation
export function validateNumber(_: number, formValus: FormValues) {
  return formValus.number1 + formValus.number2 === 3;
}

export default function App() {
  const { register, handleSubmit } = useForm({
    defaultValues: {
      number1: 0,
      number2: 0
    }
  });

  return (
    <form onSubmit={handleSubmit((data) => console.log(data))}>
      <input
        type="number"
        {...register("number1", {
          validate: validateNumber,
          valueAsNumber: true
        })}
      />
      <input
        type="number"
        {...register("number2", {
          validate: validateNumber,
          valueAsNumber: true
        })}
      />
     <button>submit</button>
    </form>
  );
}

🛤️ keep track of traversed types to avoid self-referencing while constructing paths for a type (#9540)
🏋🏻‍♀️ reduced code with unset by weight reduce of 1% (#9575)
📔 fix warning for setValue test case
🪜 Improve handleSubmit function
🙆🏻‍♂️ fix: revert fieldState.invalid deprecated (#9760)
🇪🇸 fix spanish translation (#9737)

thanks to @SimplyLinn & @Mini-ghost @mango906 @amendezm

Don't miss a new react-hook-form release

NewReleases is sending notifications on new releases.