-
-
Save iamhaiderkhan/c212e6660592a42efdba9bdd03981965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { useForm } from "react-hook-form"; | |
function SignUpComponent() { | |
const { register, handleSubmit, errors } = useForm(); | |
const onSubmit = (data) => { | |
// logs {firstName:"exampleFirstName", lastName:"exampleLastName"} | |
console.log(data); | |
}; | |
return ( | |
<form onSubmit={handleSubmit(onSubmit)}> | |
<input name="firstName" ref={register} /> | |
<input name="lastName" ref={register({ required: true })} /> | |
{errors.lastName && <span>"Last name is a mandatory field."</span>} | |
<input name="age" ref={register({ required: true })} /> | |
{errors.age && <span>"Please enter number for age."</span>} | |
<input type="submit" /> | |
</form> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment