@@ -76,6 +76,11 @@ function useWatch<TForm extends FormInstance>(
76
76
form ?: TForm | WatchOptions < TForm > ,
77
77
) : GetGeneric < TForm > ;
78
78
79
+ function useWatch < TForm extends FormInstance , TSelected = unknown > (
80
+ selector : ( values : GetGeneric < TForm > ) => TSelected ,
81
+ form ?: TForm | WatchOptions < TForm > ,
82
+ ) : TSelected ;
83
+
79
84
function useWatch < TForm extends FormInstance > (
80
85
dependencies : NamePath ,
81
86
form ?: TForm | WatchOptions < TForm > ,
@@ -86,8 +91,10 @@ function useWatch<ValueType = Store>(
86
91
form ?: FormInstance | WatchOptions < FormInstance > ,
87
92
) : ValueType ;
88
93
89
- function useWatch ( ...args : [ NamePath , FormInstance | WatchOptions < FormInstance > ] ) {
90
- const [ dependencies = [ ] , _form = { } ] = args ;
94
+ function useWatch (
95
+ ...args : [ NamePath | ( ( values : Store ) => any ) , FormInstance | WatchOptions < FormInstance > ]
96
+ ) {
97
+ const [ dependencies , _form = { } ] = args ;
91
98
const options = isFormInstance ( _form ) ? { form : _form } : _form ;
92
99
const form = options . form ;
93
100
@@ -126,7 +133,11 @@ function useWatch(...args: [NamePath, FormInstance | WatchOptions<FormInstance>]
126
133
const { registerWatch } = getInternalHooks ( HOOK_MARK ) ;
127
134
128
135
const cancelRegister = registerWatch ( ( values , allValues ) => {
129
- const newValue = getValue ( options . preserve ? allValues : values , namePathRef . current ) ;
136
+ const _values = options . preserve ? allValues : values ;
137
+ const newValue =
138
+ typeof dependencies === 'function'
139
+ ? dependencies ( _values )
140
+ : getValue ( _values , namePathRef . current ) ;
130
141
const nextValueStr = stringify ( newValue ) ;
131
142
132
143
// Compare stringify in case it's nest object
0 commit comments