never setState after component is unmounted

This commit is contained in:
Horcrux
2016-08-24 18:03:53 +08:00
parent 371cf51b0d
commit 9f5b1a26bb

View File

@@ -23,12 +23,18 @@ class GExample extends Component{
componentDidMount = () => {
setTimeout(() => {
this.setState({
fill: '#856'
});
if (!this._unmounted) {
this.setState({
fill: '#856'
});
}
}, 2000);
};
componentWillUnmount = () => {
this._unmounted = true;
};
render() {
return <Svg
height="100"