我在React Native中保存一些项目到AsyncStorage
,我使用的是Chrome调试器和iOS模拟器。React Native - 如何查看AsyncStorage中存储的内容?
没有反应过来本地,使用常规的Web开发localStorage
,我能够看到存储localStorage
项目下Chrome Debugger > Resources > Local Storage
任何想法,我怎么能查看阵营本地AsyncStorage
存储的项目?
我在React Native中保存一些项目到AsyncStorage
,我使用的是Chrome调试器和iOS模拟器。React Native - 如何查看AsyncStorage中存储的内容?
没有反应过来本地,使用常规的Web开发localStorage
,我能够看到存储localStorage
项目下Chrome Debugger > Resources > Local Storage
任何想法,我怎么能查看阵营本地AsyncStorage
存储的项目?
您可以使用reactotron我认为它有异步存储资源管理器) https://github.com/infinitered/reactotron
这不是答案吗?这是一个非常好的工具! – dericcain
随着bluebird你可以这样做:
const dumpRaw =() => {
return AsyncStorage.getAllKeys().then(keys => {
return Promise.reduce(keys, (result, key) => {
return AsyncStorage.getItem(key).then(value => {
result[key] = value;
return result;
});
}, {});
});
};
dumpRaw().then(data => console.log(data));
由于您使用的是箭头功能,因此您可以使用简写箭头功能: 而不是'a => {return b => {return c}}'你可以做'a => b => c' –
只需拨打showAsyncStorageContentInDev()
即可D控制台,您将能够看到应用程序存储的转储。
我没有发现Reactotron有任何类型的漂亮打印功能,它也是残酷的潜伏,所以我只是写了一个简单的函数使用lodash。你也可以使用下划线。
假设你把所有的密钥的静态映射...
const keys = {
key1: 'key1',
key2: 'key2'
}
export function printLocalStorage() {
_.forEach(keys, (k, v) => {
localStore.getAllDataForKey(v).then(tree => {
console.log(k) // Logs key above the object
console.log(tree) // Logs a pretty printed JSON object
})
})
}
这不是高性能的,但它解决了这个问题。
不知道是否存在这样的工具,我通常只是查询它并传递一个回调来记录它。 AsyncStorage.getItem('thing')。then((res)=> console.log(res))' – agmcleod
是的,这就是我现在要做的,但试图看看是否有可视化的方式来查看存储中的所有内容。 – Wonka
放入UI组件https://github.com/vczero/rn-cook – James