我正在将我发布的项目中的AsyncStorage
从"react-native"
迁移到'@react-native-community/async-storage'
,并且我意识到以前保存的所有数据都丢失了。不幸的是,由于这种迁移,我不能让我的零售用户丢失所有数据。是否可以将用AsyncStorage
保存的数据从"react-native"
迁移到'@react-native-community/async-storage'
?谢谢
答案 0 :(得分:1)
您可以在第一次检查新存储(来自新库)是否为空,然后尝试使用存在/旧的AsyncStorage库进行导入 到新的:
import { AsyncStorage as OldAsyncStorage} from 'react-native';
importData = () => {
OldAsyncStorage.getAllKeys.then((keys) => {
return OldAsyncStorage.multiGet(keys)
.then((result) => {
...
});
});
}
之后,使用multiSet函数将其存储到新存储中。
答案 1 :(得分:0)
我忘了提到我正在使用Expo,现在我只想使用ReactNative。我发现ReactNative核心使用@"RNCAsyncLocalStorage_V1"
而不是Expo使用@"RCTAsyncLocalStorage"
,因此目录路径不匹配。