react常见组件问题Can't perform a React state update on an unmounted component

491 阅读1分钟

在写react组件的时候,会有这个警告

这是因为在写一个方法完成请求后我们改变state状态,解决办法,react钩子:componentWillUnmount

//写一个方法完成请求后我们改变state状态,卸载,防止报错    
componentWillUnmount = () => {    
    this.setState = (state, callback) => {   
         return;       
     };    
};