@@ -49,7 +49,7 @@ interface ChildProps {
49
49
[ name : string ] : any ;
50
50
}
51
51
52
- export interface FieldProps {
52
+ export interface InternalFieldProps {
53
53
children ?:
54
54
| React . ReactElement
55
55
| ( ( control : ChildProps , meta : Meta , form : FormInstance ) => React . ReactNode ) ;
@@ -60,7 +60,7 @@ export interface FieldProps {
60
60
*/
61
61
dependencies ?: NamePath [ ] ;
62
62
getValueFromEvent ?: ( ...args : EventArgs ) => StoreValue ;
63
- name ?: NamePath ;
63
+ name ?: InternalNamePath ;
64
64
normalize ?: ( value : StoreValue , prevValue : StoreValue , allValues : Store ) => StoreValue ;
65
65
rules ?: Rule [ ] ;
66
66
shouldUpdate ?: ShouldUpdate ;
@@ -72,12 +72,16 @@ export interface FieldProps {
72
72
onReset ?: ( ) => void ;
73
73
}
74
74
75
+ export interface FieldProps extends Omit < InternalFieldProps , 'name' > {
76
+ name ?: NamePath ;
77
+ }
78
+
75
79
export interface FieldState {
76
80
resetCount : number ;
77
81
}
78
82
79
83
// We use Class instead of Hooks here since it will cost much code by using Hooks.
80
- class Field extends React . Component < FieldProps , FieldState > implements FieldEntity {
84
+ class Field extends React . Component < InternalFieldProps , FieldState > implements FieldEntity {
81
85
public static contextType = FieldContext ;
82
86
83
87
public static defaultProps = {
@@ -129,9 +133,8 @@ class Field extends React.Component<FieldProps, FieldState> implements FieldEnti
129
133
public getNamePath = ( ) : InternalNamePath => {
130
134
const { name } = this . props ;
131
135
const { prefixName = [ ] } : InternalFormInstance = this . context ;
132
- const namePath = getNamePath ( name ) ;
133
136
134
- return ' name' in this . props ? [ ...prefixName , ...namePath ] : [ ] ;
137
+ return name !== undefined ? [ ...prefixName , ...name ] : [ ] ;
135
138
} ;
136
139
137
140
public getRules = ( ) : RuleObject [ ] => {
@@ -456,4 +459,9 @@ class Field extends React.Component<FieldProps, FieldState> implements FieldEnti
456
459
}
457
460
}
458
461
459
- export default Field ;
462
+ const WrapperField : React . FC < FieldProps > = ( { name, ...restProps } ) => {
463
+ const namePath = name !== undefined ? getNamePath ( name ) : undefined ;
464
+ return < Field key = { `_${ ( namePath || [ ] ) . join ( '_' ) } ` } name = { namePath } { ...restProps } /> ;
465
+ } ;
466
+
467
+ export default WrapperField ;
0 commit comments