Applying Validations
- Create interface
interface FormData {
name: string;
age: string;
}
- Deconstruct errors
const {register, handleSubmit, formState: {errors}} = useForm<FormData>();
- Specify validation
<input {...register("name", {required: true, minLength: 3})} />
{errors.name?.type === "required" && <p>The name field is required</p> }
{errors.name?.type === "minLength" && <p>The name must be atleat 3 characters</p> }