1
1
import * as React from 'react' ;
2
2
import warning from '@rc-component/util/lib/warning' ;
3
- import type { InternalNamePath , NamePath , StoreValue , ValidatorRule , Meta } from './interface' ;
3
+ import type {
4
+ InternalNamePath ,
5
+ NamePath ,
6
+ StoreValue ,
7
+ ValidatorRule ,
8
+ Meta ,
9
+ InternalFormInstance ,
10
+ } from './interface' ;
4
11
import FieldContext from './FieldContext' ;
5
12
import Field from './Field' ;
6
13
import { move , getNamePath } from './utils/valueUtil' ;
@@ -40,18 +47,19 @@ function List<Values = any>({
40
47
} : ListProps < Values > ) {
41
48
const context = React . useContext ( FieldContext ) ;
42
49
const wrapperListContext = React . useContext ( ListContext ) ;
43
- const keyRef = React . useRef ( {
44
- keys : [ ] ,
45
- id : 0 ,
46
- } ) ;
50
+ const keyRef = React . useRef ( { keys : [ ] , id : 0 } ) ;
51
+
47
52
const keyManager = keyRef . current ;
48
53
49
- const prefixName : InternalNamePath = React . useMemo ( ( ) => {
54
+ const prefixName = React . useMemo < InternalNamePath > ( ( ) => {
50
55
const parentPrefixName = getNamePath ( context . prefixName ) || [ ] ;
51
56
return [ ...parentPrefixName , ...getNamePath ( name ) ] ;
52
57
} , [ context . prefixName , name ] ) ;
53
58
54
- const fieldContext = React . useMemo ( ( ) => ( { ...context , prefixName } ) , [ context , prefixName ] ) ;
59
+ const fieldContext = React . useMemo < InternalFormInstance > (
60
+ ( ) => ( { ...context , prefixName } ) ,
61
+ [ context , prefixName ] ,
62
+ ) ;
55
63
56
64
// List context
57
65
const listContext = React . useMemo < ListContextProps > (
@@ -62,7 +70,7 @@ function List<Values = any>({
62
70
return [ keyManager . keys [ pathName ] , namePath . slice ( len + 1 ) ] ;
63
71
} ,
64
72
} ) ,
65
- [ prefixName ] ,
73
+ [ keyManager , prefixName ] ,
66
74
) ;
67
75
68
76
// User should not pass `children` as other type.
0 commit comments