修复一个 setState 给 unMounted 组件的问题

This commit is contained in:
liaoxuezhi 2019-11-18 15:02:26 +08:00
parent 06e3eda803
commit a7aa3f0528

View File

@ -53,7 +53,8 @@ export class TooltipWrapper extends React.Component<
}; };
target: HTMLElement; target: HTMLElement;
timer: number; timer: NodeJS.Timeout;
moutned = true;
constructor(props: TooltipWrapperProps) { constructor(props: TooltipWrapperProps) {
super(props); super(props);
@ -76,6 +77,7 @@ export class TooltipWrapper extends React.Component<
componentWillUnmount() { componentWillUnmount() {
clearTimeout(this.timer); clearTimeout(this.timer);
this.moutned = false;
} }
getTarget() { getTarget() {
@ -94,6 +96,7 @@ export class TooltipWrapper extends React.Component<
hide() { hide() {
waitToHide = null; waitToHide = null;
this.moutned &&
this.setState({ this.setState({
show: false show: false
}); });