1import React from "react";
2import { useForm } from "react-hook-form";
3
4export default function App() {
5 const { register, handleSubmit, errors } = useForm();
6 const onSubmit = data => console.log(data);
7
8 return (
9 <form onSubmit={handleSubmit(onSubmit)}>
10 <input
11 type="text"
12 aria-invalid={errors.firstName ? "true" : "false"}
13 name="firstName"
14 ref={register({ required: true })}
15 />
16 { errors.firstName && (
17 <span role="alert">
18 This field is required
19 </span>
20 )
21 }
22
23 <input type="submit" />
24 </form>
25 );
26}