修复一个已销毁调用 setState 的case

This commit is contained in:
2betop 2020-05-08 17:56:41 +08:00
parent 7fa8adec80
commit 96e42c4169
1 changed files with 12 additions and 6 deletions

View File

@ -161,6 +161,7 @@ export default class ImageControl extends React.Component<
current: FileValue | FileX | null = null;
resolve?: (value?: any) => void;
emitValue: any;
unmounted = false;
constructor(props: ImageProps) {
super(props);
@ -261,6 +262,10 @@ export default class ImageControl extends React.Component<
}
}
componentWillUnmount() {
this.unmounted = true;
}
buildCrop(props: ImageProps) {
let crop = props.crop;
@ -837,12 +842,13 @@ export default class ImageControl extends React.Component<
this.current || find(files, file => file.state === 'pending')
);
this.setState(
{
files: this.files = files
},
!needUploading ? this.onChange : undefined
);
this.unmounted ||
this.setState(
{
files: this.files = files
},
!needUploading ? this.onChange : undefined
);
};
img.src = imgDom.src;
}