React native 如何解决使用异步存储(已弃用)警告的问题?使用社区(正确)图书馆
我正在使用@react native community/async storage并不断收到以下警告:React native 如何解决使用异步存储(已弃用)警告的问题?使用社区(正确)图书馆,react-native,warnings,asyncstorage,React Native,Warnings,Asyncstorage,我正在使用@react native community/async storage并不断收到以下警告: 警告:异步存储已从react native core中提取,将在将来的版本中删除。现在可以从“@react native community/async storage”而不是“react native”安装和导入它。看见https://github.com/react-native-community/react-native-async-storage import AsyncStora
警告:异步存储已从react native core中提取,将在将来的版本中删除。现在可以从“@react native community/async storage”而不是“react native”安装和导入它。看见https://github.com/react-native-community/react-native-async-storage
import AsyncStorage from '@react-native-async-storage/async-storage';
这是我的package.json:
{
"name": "mobile_app",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"@aws-amplify/pushnotification": "^1.0.32",
"@react-native-community/async-storage": "^1.6.1",
"aws-amplify": "^1.1.32",
"aws-amplify-react-native": "^2.1.15",
"buffer": "^5.3.0",
"moment": "^2.24.0",
"react": "16.8.3",
"react-native": "0.59.9",
"react-native-ble-plx": "^1.0.3",
"react-native-calendars": "^1.208.0",
"react-native-check-box": "^2.1.7",
"react-native-dialog": "^5.6.0",
"react-native-gesture-handler": "^1.3.0",
"react-native-indicators": "^0.13.0",
"react-native-keyboard-aware-scroll-view": "^0.8.0",
"react-native-modal-datetime-picker": "^7.5.0",
"react-native-modalbox": "^1.7.1",
"react-native-swipeable-row": "^0.8.1",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^3.11.0",
"react-redux": "^7.1.0",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-saga": "^1.0.5"
},
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/runtime": "^7.4.5",
"babel-jest": "^24.8.0",
"jest": "^24.8.0",
"metro-react-native-babel-preset": "^0.54.1",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"./assets/fonts/"
]
}
}
我已经删除了node_模块和Thread.lock并重新安装。此外,我还查看了我的所有依赖项(如本问题中所建议的:),其中没有一个使用不推荐使用的异步存储包
您对如何解决此警告有何建议
----编辑:
有人问我如何导入异步存储。我只在名为storage helpers的文件中的一个位置执行此操作:
import AsyncStorage from '@react-native-community/async-storage';
set_data = async (storage_key, value) => {
try {
const value_to_store = JSON.stringify(value);
return await AsyncStorage.setItem(storage_key, value_to_store);
} catch (error) {
console.log(error);
return error;
}
}
get_data = async (storage_key) => {
console.log("Getting Data", storage_key);
const value = await AsyncStorage.getItem(storage_key)
.then((returned_value) => {
const parsed = JSON.parse(returned_value);
return parsed;
})
.catch((error) => {
console.log("Get Item Error: ", error);
})
console.log("Finished Getting Data");
return value;
}
clear_data = async () => {
console.log("Clearing Persistent Storage");
return await AsyncStorage.clear();
}
module.exports = {
set_data,
get_data,
clear_data,
}
确保使用正确的导入:
import AsyncStorage from '@react-native-community/async-storage';
检查您的一个依赖项是否使用异步存储,并且他们正在直接从react导入它。查看您的依赖项列表,列表上的第一个依赖项
@aws amplify/pushnotification
使用AsyncStorage
fromreact native
您可以看到它导入异步存储
。下面是确切的一行:
import { NativeModules, DeviceEventEmitter, AsyncStorage, PushNotificationIOS, Platform, AppState } from 'react-native';
这就是为什么您会收到警告,这是由于使用AsyncStorage
import AsyncStorage from '@react-native-async-storage/async-storage';
有一个问题在五月份就已经开始了,但是后来它被标记为关闭。你可以看到这个问题
似乎
@aws-amplify/core
也使用react-native
中的AsyncStorage
您可以看到它正在RNComponents和StorageHelper中使用
最好的做法是分叉repo并修复AsyncStorage的所有实例,以使用正确的版本,或者解决一个问题
仔细检查您的依赖项始终是值得的,以查看它们实际使用的是什么。有时候,仅仅搜索他们已经安装了什么或者他们的github上有什么就足够了 似乎异步存储已移动到新组织 试一试
npm i@react本机异步存储/异步存储
import AsyncStorage from '@react-native-async-storage/async-storage';
谢谢你的建议。这就是我导入它的方式,我只在一个文件中进行导入。我添加了上面的代码。我检查了依赖项中的每个包,并查看了它们的package.json和非导入的异步存储。你建议去别的地方看看吗?谢谢你的帮助。是的,对不起,重读你的问题就知道了。除了进行全局搜索以确认它没有被导入到其他地方之外,我没有任何建议。我在VSCode中进行了全局搜索,但不幸的是,没有发现任何问题,也没有任何担心,谢谢您的时间!我注意到您建议仔细搜索每个依赖项,因为只查看它们的依赖项列表是不够的。谢谢你的指导。