@@ -7,18 +7,27 @@ import { Equal, Expect } from "../helpers/type-utils";
7
7
*
8
8
* Investigate why this is, and what TFieldValues is being used for.
9
9
*/
10
- const formWithValues = useForm ( {
11
- defaultValues : {
12
- firstName : "" ,
13
- lastName : "" ,
14
- } ,
15
- } ) ;
10
+ const Example1 = ( ) => {
11
+ const form = useForm ( {
12
+ defaultValues : {
13
+ firstName : "" ,
14
+ lastName : "" ,
15
+ } ,
16
+ } ) ;
16
17
17
- const values = formWithValues . getValues ( ) ;
18
-
19
- type test = Expect <
20
- Equal < typeof values , { firstName : string ; lastName : string } >
21
- > ;
18
+ return (
19
+ < form
20
+ onSubmit = { form . handleSubmit ( ( values ) => {
21
+ type test = Expect <
22
+ Equal < typeof values , { firstName : string ; lastName : string } >
23
+ > ;
24
+ } ) }
25
+ >
26
+ < input { ...form . register ( "firstName" ) } />
27
+ < input { ...form . register ( "lastName" ) } />
28
+ </ form >
29
+ ) ;
30
+ } ;
22
31
23
32
/**
24
33
* 2. When you don't pass a default value, the return type of getValues is
@@ -27,8 +36,17 @@ type test = Expect<
27
36
* Investigate why this is, and what type FieldValues is.
28
37
*/
29
38
30
- const formWithoutValues = useForm ( ) ;
31
-
32
- const values2 = formWithoutValues . getValues ( ) ;
39
+ const Example2 = ( ) => {
40
+ const form = useForm ( { } ) ;
33
41
34
- type test2 = Expect < Equal < typeof values2 , FieldValues > > ;
42
+ return (
43
+ < form
44
+ onSubmit = { form . handleSubmit ( ( values ) => {
45
+ type test = Expect < Equal < typeof values , FieldValues > > ;
46
+ } ) }
47
+ >
48
+ < input { ...form . register ( "firstName" ) } />
49
+ < input { ...form . register ( "lastName" ) } />
50
+ </ form >
51
+ ) ;
52
+ } ;
0 commit comments