MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / App

Function App

examples/V7/triggerFieldValidation.tsx:4–36  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { useForm } from 'react-hook-form';
3
4export 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}

Callers

nothing calls this directly

Calls 4

useFormFunction · 0.85
handleSubmitFunction · 0.85
registerFunction · 0.85
triggerFunction · 0.85

Tested by

no test coverage detected