1
1
import * as React from 'react' ;
2
2
import { ReactNode } from 'react' ;
3
- import {
4
- useWatch ,
5
- useFormContext ,
6
- FieldValues ,
7
- PathValue ,
8
- Path ,
9
- } from 'react-hook-form' ;
3
+ import { useWatch , useFormContext , FieldValues } from 'react-hook-form' ;
10
4
import get from 'lodash/get' ;
11
5
12
6
/**
@@ -50,13 +44,13 @@ import get from 'lodash/get';
50
44
const FormDataConsumer = < TFieldValues extends FieldValues = FieldValues > (
51
45
props : ConnectedProps < TFieldValues >
52
46
) => {
53
- const { getValues } = useFormContext ( ) ;
54
- const formData = useWatch < TFieldValues > ( ) ;
47
+ const { getValues } = useFormContext < TFieldValues > ( ) ;
48
+ let formData = ( useWatch < TFieldValues > ( ) as unknown ) as TFieldValues ;
55
49
56
50
//useWatch will initially return the provided defaultValues of the form.
57
51
//We must get the initial formData from getValues
58
52
if ( Object . keys ( formData ) . length === 0 ) {
59
- ( formData as FieldValues ) = getValues ( ) ;
53
+ formData = getValues ( ) ;
60
54
}
61
55
62
56
return (
@@ -65,10 +59,9 @@ const FormDataConsumer = <TFieldValues extends FieldValues = FieldValues>(
65
59
} ;
66
60
67
61
export const FormDataConsumerView = <
68
- TFieldValues extends FieldValues = FieldValues ,
69
- TPathValue = PathValue < TFieldValues , Path < TFieldValues > > [ ]
62
+ TFieldValues extends FieldValues = FieldValues
70
63
> (
71
- props : Props < TPathValue >
64
+ props : Props < TFieldValues >
72
65
) => {
73
66
const { children, form, formData, source, index, ...rest } = props ;
74
67
let ret ;
0 commit comments