修复 crud 列切换和拖拽不渲染的问题

This commit is contained in:
liaoxuezhi 2020-08-27 10:44:53 +08:00
parent cedcc9e62b
commit bf6db5feab
2 changed files with 16 additions and 3 deletions

View File

@ -53,6 +53,7 @@ export class TableContent extends React.Component<TableContentProps> {
super(props);
const rows = props.rows;
this.reaction = reaction(
() => `${rows.map(item => item.id).join(',')}`,
() => this.forceUpdate(),
@ -62,7 +63,13 @@ export class TableContent extends React.Component<TableContentProps> {
);
}
shouldComponentUpdate() {
shouldComponentUpdate(nextProps: TableContentProps) {
const props = this.props;
if (props.columns !== nextProps.columns) {
return true;
}
return false;
}

View File

@ -34,11 +34,12 @@ export class TableRow extends React.Component<TableRowProps> {
const item = props.item;
const parent = props.parent;
const columns = props.columns;
this.reaction = reaction(
() =>
`${item.isHover}${item.checked}${JSON.stringify(item.data)}${
item.moved
}${item.modified}${item.expanded}${parent?.expanded}`,
}${item.modified}${item.expanded}${parent?.expanded}${columns.length}`,
() => this.forceUpdate(),
{
onError: () => this.reaction!()
@ -46,7 +47,12 @@ export class TableRow extends React.Component<TableRowProps> {
);
}
shouldComponentUpdate() {
shouldComponentUpdate(nextProps: TableRowProps) {
const props = this.props;
if (props.columns !== nextProps.columns) {
return true;
}
// 不需要更新,因为孩子节点已经 observer 了
return false;
}