Skip to content

Commit b9e850c

Browse files
adamivanczamastermoo
authored andcommitted
Prevent to update state after unmounting component (#287)
1 parent b813173 commit b9e850c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ActionButton.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ export default class ActionButton extends Component {
3030
this.timeout = null;
3131
}
3232

33+
componentDidMount() {
34+
this.mounted = true;
35+
}
36+
3337
componentWillUnmount() {
38+
this.mounted = false;
3439
clearTimeout(this.timeout);
3540
}
3641

@@ -326,10 +331,11 @@ export default class ActionButton extends Component {
326331
this.anim.setValue(0);
327332
}
328333

329-
setTimeout(
330-
() => this.setState({ active: false, resetToken: this.state.resetToken }),
331-
250
332-
);
334+
setTimeout(() => {
335+
if (this.mounted) {
336+
this.setState({ active: false, resetToken: this.state.resetToken });
337+
}
338+
}, 250);
333339
}
334340
}
335341

0 commit comments

Comments
 (0)