@@ -2,7 +2,7 @@ import type { FormInstance } from '.';
2
2
import { FieldContext } from '.' ;
3
3
import warning from 'rc-util/lib/warning' ;
4
4
import { HOOK_MARK } from './FieldContext' ;
5
- import type { InternalFormInstance , NamePath , Store } from './interface' ;
5
+ import type { InternalFormInstance , InternalNamePath , NamePath , Store } from './interface' ;
6
6
import { useState , useContext , useEffect , useRef , useMemo } from 'react' ;
7
7
import { getNamePath , getValue } from './utils/valueUtil' ;
8
8
@@ -17,6 +17,19 @@ export function stringify(value: any) {
17
17
}
18
18
}
19
19
20
+ const useWatchWarning =
21
+ process . env . NODE_ENV !== 'production'
22
+ ? ( namePath : InternalNamePath ) => {
23
+ const fullyStr = namePath . join ( '__RC_FIELD_FORM_SPLIT__' ) ;
24
+ const nameStrRef = useRef ( fullyStr ) ;
25
+
26
+ warning (
27
+ nameStrRef . current === fullyStr ,
28
+ '`useWatch` is not support dynamic `namePath`. Please provide static instead.' ,
29
+ ) ;
30
+ }
31
+ : ( ) => { } ;
32
+
20
33
function useWatch <
21
34
TDependencies1 extends keyof GetGeneric < TForm > ,
22
35
TForm extends FormInstance ,
@@ -82,6 +95,8 @@ function useWatch(...args: [NamePath, FormInstance]) {
82
95
const namePathRef = useRef ( namePath ) ;
83
96
namePathRef . current = namePath ;
84
97
98
+ useWatchWarning ( namePath ) ;
99
+
85
100
useEffect (
86
101
( ) => {
87
102
// Skip if not exist form instance
0 commit comments