5 changed files with 59 additions and 51 deletions
@ -0,0 +1,26 @@ |
|||||
|
|
||||
|
import { SubmitHandler, useForm } from "react-hook-form"; |
||||
|
|
||||
|
interface IProps { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
type Inputs = { |
||||
|
email: string, |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
export function Login(props: IProps) { |
||||
|
const { register, handleSubmit, watch, formState: { errors } } = useForm<Inputs>(); |
||||
|
const onSubmit: SubmitHandler<Inputs> = data => console.log(data); |
||||
|
|
||||
|
console.log(watch("email")); |
||||
|
|
||||
|
return <> |
||||
|
<form onSubmit={handleSubmit(onSubmit)}> |
||||
|
<input {...register("email", { required: true })} /> |
||||
|
{errors.email && <span>This field is required</span>} |
||||
|
<input type="submit" /> |
||||
|
</form> |
||||
|
</> |
||||
|
} |
Loading…
Reference in new issue