@@ -2,7 +2,7 @@ import type { FormInstance } from '.';
22import { FieldContext } from '.' ;
33import warning from 'rc-util/lib/warning' ;
44import { HOOK_MARK } from './FieldContext' ;
5- import type { InternalFormInstance , NamePath , Store } from './interface' ;
5+ import type { InternalFormInstance , InternalNamePath , NamePath , Store } from './interface' ;
66import { useState , useContext , useEffect , useRef , useMemo } from 'react' ;
77import { getNamePath , getValue } from './utils/valueUtil' ;
88
@@ -17,6 +17,19 @@ export function stringify(value: any) {
1717 }
1818}
1919
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+
2033function useWatch <
2134 TDependencies1 extends keyof GetGeneric < TForm > ,
2235 TForm extends FormInstance ,
@@ -82,6 +95,8 @@ function useWatch(...args: [NamePath, FormInstance]) {
8295 const namePathRef = useRef ( namePath ) ;
8396 namePathRef . current = namePath ;
8497
98+ useWatchWarning ( namePath ) ;
99+
85100 useEffect (
86101 ( ) => {
87102 // Skip if not exist form instance
0 commit comments