Skip to content

Instantly share code, notes, and snippets.

@Gauthamjm007
Created May 23, 2020 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gauthamjm007/692f46a93b563bea80bba804bca9bd25 to your computer and use it in GitHub Desktop.
Save Gauthamjm007/692f46a93b563bea80bba804bca9bd25 to your computer and use it in GitHub Desktop.
React hooks form ,login component
import React from "react";
import { useForm } from "react-hook-form";
const Login = () => {
const { handleSubmit, register, errors } = useForm();
const onSubmit = (values) => console.log(values);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input
name="email"
ref={register({
required: "Required",
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
message: "invalid email address",
},
})}
/>
{errors.email && errors.email.message}
<input
name="password"
ref={register({
required: "Required",
pattern: {
value: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/i,
message: "Minimum eight characters, at least one uppercase letter, one lowercase letter and one number",
},
})}
/>
{errors.password && errors.password.message}
<button type="submit">Submit</button>
</form>
);
};
export default Login;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment