Answers for "how to use error in react hook form"

-1

how to use error in react hook form

import {useForm} from 'react-hook-form';
const {register,handleSubmit,formState: { errors }} = useForm();
<form onSubmit={handleSubmit(onSubmit)}>
<input name='to' placeholder="To" type="text" {...register("to",{ required: true })}/>
{errors.to && <p className="sendMail_error">To is required</p>}
 </form>
Posted by: Guest on April-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language