componentWillUnmount()
在组件被卸载或者销毁的时候执行,方法中不能再有setState的动作。
setState
一般用作清除组件中起的定义器、webSocket等。
webSocket
示例:
componentWillUnmount() { if(this.timer) { window.clearInterval(this.timer); this.timer = null; } }
在线示例