运行报错 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.

内存泄漏,需要销毁

componentDidMount(){
this.timer=setInterval (
()=>{
let opacity = this.state.opacity;
opacity -= .05;
if (opacity < 0.1) {
opacity = 1.0;
}
this.setState({
opacity: opacity
});
},100)
}
componentWillUnmount() {
// 如果存在this.timer,则使用clearTimeout清空。
// 如果你使用多个timer,那么用多个变量,或者用个数组来保存引用,然后逐个clear
clearTimeout(this.timer);
}

 

posted @ 2017-01-19 14:06  李元夕cool  阅读(385)  评论(0编辑  收藏  举报