From 96e42c416980129ff11479dae4bc390e7e6547cf Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Fri, 8 May 2020 17:56:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA=E5=B7=B2?= =?UTF-8?q?=E9=94=80=E6=AF=81=E8=B0=83=E7=94=A8=20setState=20=E7=9A=84case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Form/Image.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/renderers/Form/Image.tsx b/src/renderers/Form/Image.tsx index ab25a454..cef2f080 100644 --- a/src/renderers/Form/Image.tsx +++ b/src/renderers/Form/Image.tsx @@ -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; }