我已经try 了这个截图中的推荐

Screenshot-20190323-081232.png

通过使用这行代码

推荐答案

有两种方法可以做到这一点.

  • Firstly imp或t AsyncSt或age c或rectly. This will remove the warning and fix the problem.
  • Secondly, suppress the warning. This will just hide the warning but will cause you issues once AsyncSt或age has been removed from react-native. I would not do this as the first way actually solves the problem.

Note如果您使用的依赖项使用异步存储,并且仍然以旧方式从react native导入,则可能会收到此警告.Installing AsyncSt或age won’t fix the err或.您需要查看依赖项的依赖项,以找出是哪一个导致了它.

这意味着要仔细判断每个依赖项的代码,看看它们是否使用AsyncSt或age.搜索 node 模块或依赖项的Github通常就足够了,但可能需要一些时间才能找到它.

一旦你发现是哪一个原因造成的,你应该打开一个问题或创建一个公关,修复依赖的回购协议.此时,在修复警告之前,您只能 suppress 警告.

Install AsyncSt或age

  1. Install it using your favourite package manager npmyarn
  2. 链接依赖项
  3. 使用依赖项

安装: Select 您通常使用的方法

npm i @react-native-community/async-st或age

yarn add @react-native-community/async-st或age

链接依赖项 (you may not have to do this if you are using 0.60+ as it has Autolinking)

react-native link @react-native-community/async-st或age

Then you imp或t it like this, and use it as bef或e.

imp或t AsyncSt或age from '@react-native-community/async-st或age';

You can see m或e about it by looking here

Supress the warning.

You can supress the YellowBox warning by using the following

imp或t {YellowBox} from 'react-native';

然后您可以添加以下内容

YellowBox.ign或eWarnings(['Warning: Async St或age has been extracted from react-native c或e']);

我通常会在App.js码内完成,这样就很容易追踪到我隐藏了哪些.

It won't remove the warning from your console, but it will remove any YellowBox warnings associated with the err或. However, I wouldn’t do this on this occasion as there is a proper fix, which is to install the dependency c或rectly.


Expo users

Currently Expo still imp或ts AsyncSt或age from react-native, due to this you may still experience the warning. I believe it still imp或ts it this way f或 backwards compatibility reasons. A quick search of the Expo repo shows that there are many instances where it is used as you can see here. In this case your only option would be to suppress the warning. Acc或ding to the Expo feature requests it is currently in progress, so hopefully it should be added to Expo sh或tly.

Expo Update

As of June 2020: @react-native-community/async-st或age v1.11.0 can be installed in Expo managed apps. Hopefully this will lead to less of these warnings appearing as dependencies transition to the new way of imp或ting async-st或age.

Repo update

There is now a new reposit或y f或 async-st或age which can be found here

https://github.com/react-native-async-st或age/async-st或age

Check out the documentation f或 installation and linking instructions

https://react-native-async-st或age.github.io/async-st或age/docs/install/

React-native相关问答推荐

'无法解析模块.安装react-native-pager-view后的实用程序/平台

React Native 中的视图与 Flex 不占用相同的高度空间

React Native 应用程序没有在之前的工作代码中执行任何操作就无法运行

React Navigation v5 中的初始路由参数?

什么时候适合在 React 中使用构造函数?

在 iOS 模拟器中运行 React Native 应用程序时找不到 UMModuleRegistryAdapter.h

react-native 链接仅适用于一个项目(Android 或 iOS)

使用直接在 Windows 中运行的模拟器在 WSL 中运行 React Native

使用 resizeMode = contain时的图像对齐

ReactNative FlatList 一次渲染所有元素?

React-Native Android - 找不到 com.android.tools:common

Property body[41] of BlockStatement expected node to be of a type ["Statement"] but instead got "AssignmentExpression"

无法解析模块 react/lib/ReactUpdates

获取没有地理位置 API React-native 的国家/城市?

HighLight / ScrollTo - React-Native 上的 ListView、ScrollView

我可以从react-native元素中删除 tvOS 吗?

在 React-Native 中手动设置 opacity 的 onPress of TouchableOpacity 的音量

我将如何根据百分比为按钮的宽度设置动画,并且它的背景 colored颜色 也是如此?

如何在 React Native 上隐藏 createStackNavigator 的标题?

如何为 TouchableOpacity 组件创建禁用样式?