-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
41 lines (38 loc) · 1018 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { useForm } from "react-hook-form";
const App = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm();
const onSubmit = (data) => {
console.log(data);
};
console.log(errors.userName);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<div
style={{
position: "absolute",
top: "40%",
left: "42%",
display: "flex",
flexDirection: "column"
}}>
<h2>Enter Name</h2>
<input
type="text"
{...register("userName", { required: true, minLength: 2 })}
/>
{errors.userName && errors.userName.type === "required" && (
<p className="error">Name is required</p>
)}
{errors.userName && errors.userName.type === "minLength" && (
<p className="error">MinLenght of two character required</p>
)}
<button className="btn" type="submit">Enviar pedido</button>
</div>
</form>
);
};
export default App;