react-native - 如何删除 'Warning: Async Storage has been extracted from react-native core…'?

标签 react-native

我已经尝试过此屏幕截图中的建议

Screenshot-20190323-081232.png

通过使用这一行代码
我要从import AsyncStorage from '../../../node_modules/@react-native-community/async-storage';导入async-storage的文件中的react-native但是此路径无法解析,即该目录中不存在async-storage。我还尝试通过运行async-storage来安装yarn add async-storage(即使它已经安装了),但是在前面提到的目录中没有任何显示

最佳答案

有两种方法可以执行此操作。

  • 首先正确导入AsyncStorage。这将删除警告并解决问题。
  • 其次,取消警告。这只会隐藏警告,但是一旦从AsyncStorage中删除了react-native,就会引起您的问题。我不会这样做,因为这实际上是解决问题的第一种方法。

  • Note you can get this warning if you are using a dependency that uses AsyncStorage and still imports it the old way from react-native. Installing AsyncStorage won’t fix the error. You will need to look through your dependencies’ dependencies to find out which one is causing it.

    This means actually going through the code of each your dependencies to see if they use AsyncStorage. Searching through your node modules or on the dependency's Github usually is sufficient but it can take some time to find it.

    Once you have found out which one is causing it, you should open an issue or create a PR with a fix on the dependency’s repo. At this point suppressing the warning is all you can do until it is fixed.


    安装AsyncStorage
  • 使用您最喜欢的软件包管理器npmyarn
  • 安装它
  • 链接依赖项
  • 使用依赖项

  • 安装:选择通常使用的方法
    npm i @react-native-community/async-storage
    
    要么
    yarn add @react-native-community/async-storage
    
    链接依赖项(如果您使用的是0.60+,则不必这样做,因为它具有Autolinking)
    react-native link @react-native-community/async-storage
    
    然后像这样导入它,并像以前一样使用它。
    import AsyncStorage from '@react-native-community/async-storage';
    
    您可以通过查看here了解更多信息
    停止警告。
    您可以使用以下命令禁止YellowBox警告
    import {YellowBox} from 'react-native';
    
    然后您可以添加以下内容
    YellowBox.ignoreWarnings(['Warning: Async Storage has been extracted from react-native core']);
    
    我通常在App.js中执行此操作,因此很容易跟踪我隐藏了哪些内容。
    它不会从您的控制台中删除该警告,但会删除与该错误相关的所有YellowBox警告。 但是,由于可以正确安装依赖项,因此我不会在这种情况下执行此操作。

    世博用户
    目前,Expo仍从AsyncStorage导入react-native,因此,您可能仍然会遇到警告。我相信出于向后兼容的原因,它仍然以这种方式导入它。快速浏览Expo仓库显示,有很多实例在使用它,如您所见here。在这种情况下,您唯一的选择是禁止显示警告。根据Expo功能的要求,它是currently in progress,因此希望可以将其不久后添加到Expo中。
    博览会更新
    截至2020年6月:可以在Expo管理的应用程序中安装@react-native-community/async-storage v1.11.0。希望这将导致较少的警告出现,因为依赖项已转换为导入异步存储的新方法。

    关于react-native - 如何删除 'Warning: Async Storage has been extracted from react-native core…'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55311228/

    相关文章:

    reactjs - 如何使用 React Router 在 React 中正确同步 useEffect 和 useLocation Hook ?

    javascript - 在两个独立的项目 React Js 和 React Native 之间共享代码的最佳解决方案? (如 redux 商店)

    javascript - 需要在 react 导航中设置默认 Prop

    reactjs - 如何限制React native ios/android日期选择器中的日期选择

    javascript - 轮询和更新状态除非特定的 prop 更新

    react-native - 在 React Native 中,如何将一个 View 放在另一个 View 之上,并且其中一部分位于后面 View 的边界之外?

    reactjs - Jest 和 React Native : How to mock AccessibilityInfo

    javascript - 调用请求后如何重新渲染屏幕?

    ios - 在 CI 构建中使用 Facebook iOS SDK - 未找到框架

    npm - react native 初始化挂起