有两种方法可以做到这一点.
AsyncSt或age
c或rectly. This will remove the warning and fix the problem.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 警告.
npm
或 yarn
安装: 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
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.
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.
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.
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/