Skip to content

Commit

Permalink
自定义组件重新渲染问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed May 13, 2020
1 parent 9e89a14 commit f4af7dd
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/renderers/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Spinner from '../../components/Spinner';
import {LazyComponent} from '../../components';
import {isAlive} from 'mobx-state-tree';
import {asFormItem} from './Item';
import {SimpleMap} from '../../utils/SimpleMap';
export type FormGroup = FormSchema & {
title?: string;
className?: string;
Expand Down Expand Up @@ -176,6 +177,7 @@ export default class Form extends React.Component<FormProps, object> {
trailing: true,
leading: false
});
componentCache: SimpleMap = new SimpleMap();
constructor(props: FormProps) {
super(props);

Expand Down Expand Up @@ -315,6 +317,7 @@ export default class Form extends React.Component<FormProps, object> {
this.lazyHandleChange.cancel();
this.asyncCancel && this.asyncCancel();
this.disposeOnValidate && this.disposeOnValidate();
this.componentCache.dispose();
const store = this.props.store;

if (
Expand Down Expand Up @@ -1008,11 +1011,19 @@ export default class Form extends React.Component<FormProps, object> {
}

if (control.component && control.label && control.name) {
control.component = asFormItem(
control.options || {
strictMode: false
}
)(control.component);
const cache = this.componentCache.get(control.component);

if (cache) {
control.component = cache;
} else {
const cache = asFormItem(
control.options || {
strictMode: false
}
)(control.component);
this.componentCache.set(control.component, cache);
control.component = cache;
}
}

control.hiddenOn && (subSchema.hiddenOn = control.hiddenOn);
Expand Down

0 comments on commit f4af7dd

Please sign in to comment.