【问题标题】:How to perfect fix isMounted(...) warnings in react-native not to silence this warning如何在 react-native 中完美修复 isMounted(...) 警告而不是使此警告静音
【发布时间】:2018-11-20 19:50:49
【问题描述】:

我收到此警告:

Warning: isMounted(...) is deprecated in plain JavaScript React classes. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks.

如何修复警告?我不想像这样隐藏它:

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module 
RCTImageLoader']);

【问题讨论】:

标签: react-native warnings


【解决方案1】:

所有 cmets 都向您展示了如何隐藏它,但没有展示如何解决它,因为误报已在 React Native 中得到修复。

我在我的 React Native 代码中使用了变量名称 isMounted,它是类上的一个自定义实例变量。但是,这与已弃用的变量 isMounted 冲突,该变量天生就在 Component 类上 - 因此发出警告。

为了解决这个问题,我简单地将我的 isMounted 变量名重命名为 mounted

【讨论】:

    猜你喜欢
    • 2019-12-07
    • 2018-11-08
    • 1970-01-01
    • 2023-01-04
    • 2021-05-11
    • 2018-02-07
    • 1970-01-01
    • 2019-06-30
    • 1970-01-01
    相关资源
    最近更新 更多