1
1
import toChildrenArray from 'rc-util/lib/Children/toArray' ;
2
2
import warning from 'rc-util/lib/warning' ;
3
+ import isEqual from 'rc-util/lib/isEqual' ;
3
4
import * as React from 'react' ;
4
5
import type {
5
6
FieldEntity ,
@@ -54,6 +55,8 @@ interface ChildProps {
54
55
[ name : string ] : any ;
55
56
}
56
57
58
+ export type MetaEvent = Meta & { destroy ?: boolean } ;
59
+
57
60
export interface InternalFieldProps < Values = any > {
58
61
children ?:
59
62
| React . ReactElement
@@ -77,7 +80,7 @@ export interface InternalFieldProps<Values = any> {
77
80
messageVariables ?: Record < string , string > ;
78
81
initialValue ?: any ;
79
82
onReset ?: ( ) => void ;
80
- onMetaChange ?: ( meta : Meta & { destroy ?: boolean } ) => void ;
83
+ onMetaChange ?: ( meta : MetaEvent ) => void ;
81
84
preserve ?: boolean ;
82
85
83
86
/** @private Passed by Form.List props. Do not use since it will break by path check. */
@@ -221,10 +224,23 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
221
224
} ) ) ;
222
225
} ;
223
226
227
+ // Event should only trigger when meta changed
228
+ private metaCache : MetaEvent = null ;
229
+
224
230
public triggerMetaEvent = ( destroy ?: boolean ) => {
225
231
const { onMetaChange } = this . props ;
226
232
227
- onMetaChange ?.( { ...this . getMeta ( ) , destroy } ) ;
233
+ if ( onMetaChange ) {
234
+ const meta = { ...this . getMeta ( ) , destroy } ;
235
+
236
+ if ( ! isEqual ( this . metaCache , meta ) ) {
237
+ onMetaChange ( meta ) ;
238
+ }
239
+
240
+ this . metaCache = meta ;
241
+ } else {
242
+ this . metaCache = null ;
243
+ }
228
244
} ;
229
245
230
246
// ========================= Field Entity Interfaces =========================
0 commit comments