mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 01:41:39 +00:00
fix memory leak warning, clear timer when the component unmounts (#6641)
* fix memory leak warning, clear timer when the component unmounts * clean up redundant check
This commit is contained in:
@@ -6,6 +6,8 @@ import Alert from './alert';
|
|||||||
const ANIMATION_DURATION = 240;
|
const ANIMATION_DURATION = 240;
|
||||||
|
|
||||||
export default class Toast extends React.PureComponent {
|
export default class Toast extends React.PureComponent {
|
||||||
|
_isMounted = false;
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
/**
|
/**
|
||||||
* The z-index of the toast.
|
* The z-index of the toast.
|
||||||
@@ -67,10 +69,12 @@ export default class Toast extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
this._isMounted = true;
|
||||||
this.startCloseTimer();
|
this.startCloseTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
this._isMounted = false;
|
||||||
this.clearCloseTimer();
|
this.clearCloseTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,9 +84,11 @@ export default class Toast extends React.PureComponent {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
this.clearCloseTimer();
|
this.clearCloseTimer();
|
||||||
this.setState({
|
if (this._isMounted) {
|
||||||
isShown: false
|
this.setState({
|
||||||
});
|
isShown: false
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
startCloseTimer = () => {
|
startCloseTimer = () => {
|
||||||
|
Reference in New Issue
Block a user