The <errorMessage> component, useWatch() hook and multi-page funnel useForm().
npm install @hookform/error-message
import { ErrorMessage } from "@hookform/error-message"//We need the criteriaMode to render multiple errors
const {register, formState: {errors}}= useForm({ criteriaMode: "all" })
<form>
<input {...methods.register("Terzo", {
minLength: { value: 5, message: "too long sorry" },
validate: (value)=>{ return (value.length>1) && "Too long again" }
})} />
<ErrorMessage errors={methods.formState.errors} name="Terzo" as="p" />
<ErrorMessage
errors={methods.formState.errors} name="Terzo"
render={({ message }) => <p className="text-warning">{message}</p>}
/>
</form>
The useWatch() method
Multi-Step Form with local-state-machine
PreviousThe fieldArray structure and methods on useForm()NextNested useForm() inputs, Self-Rendering useForm(), Yup schemas validation and React-window inputs
Last updated