无法对卸载的组件执行 React 状态更新。 2021年

时间:2021-07-12 23:04:45

标签: react-native

错误显示控制台 --> 无法对卸载的组件执行 React 状态更新。这是一个空操作,但它表明您的应用程序中存在内存泄漏。要修复,请取消 componentWillUnmount 方法中的所有订阅和异步任务。

描述问题: 我在 React Native 类组件中开发的应用程序中遇到以下问题,我在此处的论坛中找到的解决方案是将 下一个:

_isMounted = false;
componentDidMount = async () => {
         this._isMounted = true;
this.unsubscribe = auth (). onAuthStateChanged (this.onAuthStateChanged);
};

     componentWillUnmount () {
         this._isMounted = false;
this.unsubscribe ();
}

所以我使用它然后它为我产生了问题在开发模式下错误并不总是消失它可以完美运行但在生产模式下它不会。

0 个答案:

没有答案