react hook form not wo on react component code example
Example 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>
Example 2: react hook form submit outside form
const { handleSubmit } = useForm();
const onSubmit = data => {
console.log(data);
};
<form id="hook-form" onSubmit={handleSubmit(onSubmit)}>
{}
</form>
<button type="submit" form="hook-form">Submit</button>