@@ -76,6 +76,11 @@ function useWatch<TForm extends FormInstance>(
7676 form ?: TForm | WatchOptions < TForm > ,
7777) : GetGeneric < TForm > ;
7878
79+ function useWatch < TForm extends FormInstance , TSelected = unknown > (
80+ selector : ( values : GetGeneric < TForm > ) => TSelected ,
81+ form ?: TForm | WatchOptions < TForm > ,
82+ ) : TSelected ;
83+
7984function useWatch < TForm extends FormInstance > (
8085 dependencies : NamePath ,
8186 form ?: TForm | WatchOptions < TForm > ,
@@ -86,8 +91,10 @@ function useWatch<ValueType = Store>(
8691 form ?: FormInstance | WatchOptions < FormInstance > ,
8792) : ValueType ;
8893
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 ;
9198 const options = isFormInstance ( _form ) ? { form : _form } : _form ;
9299 const form = options . form ;
93100
@@ -126,7 +133,11 @@ function useWatch(...args: [NamePath, FormInstance | WatchOptions<FormInstance>]
126133 const { registerWatch } = getInternalHooks ( HOOK_MARK ) ;
127134
128135 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 ) ;
130141 const nextValueStr = stringify ( newValue ) ;
131142
132143 // Compare stringify in case it's nest object
0 commit comments