我一直在寻找解决我的问题的方法,但没有找到任何可行的方法。
目前我有一个从 AsyncStorage 获取对象数组的函数。
const get = async (key) => {
try {
const value = await AsyncStorage.getItem(prefix + key);
const item = JSON.parse(value);
console.log("From get" + JSON.stringify(item.value));
return item.value;
} catch (error) {
console.log("Error" + error);
}
};
这就是我得到的console.log
From get[{"id":1,"name":"Push Up","sets":[{"reps":"","weight":""}]},{"id":2,"name":"Pull Up","sets":[{"reps":"","weight":""}]},{"id":3,"name":"Bicep Curl","sets":[{"reps":"","weight":""}]}]
我正在尝试从像这样的另一个组件中获取值
const getCacheData = (item) => {
const data = cache.get(item.toString());
console.log("Get Cache Data" + JSON.stringify(data));
};
Console.log印刷Get Cache Data{"_U":0,"_V":0,"_W":null,"_X":null}
如果我将 getCache 变成一个async函数 and await cache.get(),那么我会收到以下错误 -
Error: Objects are not valid as a React child (found: object with keys {_U, _V, _W, _X}). If you meant to render a collection of children, use an array instead.
我不确定我在这里做错了什么?它在get()函数中按我希望的那样工作,但在另一个函数中却没有按预期工作。
感谢您查看这个!!