react-hook-form
Advanced tools
Changelog
[7.43.0] - 2023-01-30
const onSubmit = async () => {
setError('root.serverError', {
type: response.statusCode,
});
};
const onClick = () => {
setError('root.random', {
type: 'random',
});
};
return (
<>
{errors.root.serverError.type === 400 && <p>server response message</p>}
<p>{errors.root?.random?.message}</p>
</>
);
Changelog
[7.42.0] - 2023-01-13
validate
support second argument for form values// Making exported validate function isolated for validation
export function validateNumber(_: number, formValus: FormValues) {
return formValus.number1 + formValus.number2 === 3;
}
<input
type="number"
{...register('number1', {
validate: validateNumber,
valueAsNumber: true,
})}
/>;
handleSubmit
no longer catch onSubmit
callback errorfieldState.invalid