Skip to content

Commit 5d5d964

Browse files
committed
Missing clearTimeout()
I'm getting warning "Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component." without clearTimeout() in React componentWillUnmount() method.
1 parent c725d61 commit 5d5d964

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/ProgressBar.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ class ProgressBar extends React.Component {
3232
if (this.interval) {
3333
clearInterval(this.interval);
3434
}
35+
if (this.timeout) {
36+
clearTimeout(this.timeout);
37+
}
3538
};
3639

3740
componentWillReceiveProps = (nextProps) => {
3841
if (this.interval) {
3942
clearInterval(this.interval);
4043
}
44+
if (this.timeout) {
45+
clearTimeout(this.timeout);
46+
}
4147

4248
if (nextProps.autoIncrement && nextProps.percent >= 0 && nextProps.percent < 99) {
4349
this.interval = setInterval(this.increment, nextProps.intervalTime);
@@ -47,7 +53,7 @@ class ProgressBar extends React.Component {
4753
this.setState({
4854
percent: 99.9
4955
}, () => {
50-
setTimeout(() => {
56+
this.timeout = setTimeout(() => {
5157
this.setState({
5258
percent: -1
5359
});

0 commit comments

Comments
 (0)