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

Function FormState

app/src/formState.tsx:7–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5let renderCounter = 0;
6
7const FormState = () => {
8 const { mode } = useParams();
9 const {
10 register,
11 handleSubmit,
12 formState: {
13 dirtyFields,
14 isSubmitted,
15 submitCount,
16 touchedFields,
17 isDirty,
18 isSubmitting,
19 isSubmitSuccessful,
20 isValid,
21 },
22 reset,
23 } = useForm<{
24 firstName: string;
25 lastName: string;
26 select: string;
27 radio: string | null;
28 checkbox: boolean;
29 ['checkbox-checked']: boolean;
30 }>({
31 mode: mode as keyof ValidationMode,
32 defaultValues: {
33 firstName: '',
34 lastName: '',
35 select: '',
36 checkbox: false,
37 radio: null,
38 'checkbox-checked': true,
39 },
40 });
41
42 renderCounter++;
43
44 return (
45 <form
46 onSubmit={handleSubmit((d) => {
47 console.log(d);
48 })}
49 >
50 <input
51 {...register('firstName', { required: true })}
52 placeholder="firstName"
53 />
54 <input
55 {...register('lastName', { required: true })}
56 placeholder="lastName"
57 />
58 <div id="state">
59 {JSON.stringify({
60 isSubmitted,
61 submitCount,
62 isDirty,
63 isSubmitting,
64 isSubmitSuccessful,

Callers

nothing calls this directly

Calls 4

useFormFunction · 0.85
handleSubmitFunction · 0.85
registerFunction · 0.85
resetFunction · 0.85

Tested by

no test coverage detected