()
| 2 | import { useForm } from 'react-hook-form'; |
| 3 | |
| 4 | export default function App() { |
| 5 | const { |
| 6 | register, |
| 7 | formState: { errors }, |
| 8 | trigger, |
| 9 | handleSubmit, |
| 10 | } = useForm(); |
| 11 | |
| 12 | console.log('errors', errors); |
| 13 | |
| 14 | return ( |
| 15 | <form onSubmit={handleSubmit((data) => console.log(data))}> |
| 16 | <h1>validationField</h1> |
| 17 | <label>First name: </label> |
| 18 | <input {...register('firstName', { required: true })} /> |
| 19 | |
| 20 | <label>Last name: </label> |
| 21 | <input {...register('lastName', { required: true })} /> |
| 22 | |
| 23 | <button |
| 24 | type="button" |
| 25 | onClick={async () => { |
| 26 | const result = await trigger(['firstName', 'lastName']); |
| 27 | if (result) { |
| 28 | console.log('Valid input'); |
| 29 | } |
| 30 | }} |
| 31 | > |
| 32 | Trigger |
| 33 | </button> |
| 34 | </form> |
| 35 | ); |
| 36 | } |
nothing calls this directly
no test coverage detected