fix: 优化 inputTable state 更新逻辑,减少多余重新渲染 (#10464)

This commit is contained in:
liaoxuezhi 2024-06-18 11:05:18 +08:00 committed by GitHub
parent e6f2b5146a
commit 9d4c34be69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -369,7 +369,7 @@ export default class FormTable extends React.Component<TableProps, TableState> {
};
}
if (props.value !== prevProps.value) {
if (props.value !== prevProps.value && props.value !== this.emittedValue) {
toUpdate = {
...toUpdate,
items: Array.isArray(props.value) ? props.value.concat() : [],
@ -494,12 +494,17 @@ export default class FormTable extends React.Component<TableProps, TableState> {
return msg;
}
emittedValue: any = null;
async emitValue(value?: any[]) {
const items =
value ?? this.state.items.filter(item => !item.__isPlaceholder);
const {onChange} = this.props;
const isPrevented = await this.dispatchEvent('change');
isPrevented || onChange?.(items);
if (!isPrevented) {
this.emittedValue = items;
onChange?.(items);
}
return isPrevented;
}