当将AsyncStorage作为存储引擎传递时,我得到以下错误:
WARN Possible Unhandled Promise Rejection (id: 0):
Error: [AsyncStorage] Passing null/undefined as value is not supported. If you want to remove value, Use .removeItem method instead.
Passed value: undefined
Passed key: [EasyPeasyStore][0]这是我的商店声明:
import { action, createStore, persist } from "easy-peasy";
import AsyncStorage from "@react-native-async-storage/async-storage";
const store = createStore(
persist({
...my state goes here
}, {
storage: AsyncStorage
})
);发布于 2022-03-18 22:37:12
尝试添加“允许”属性
const store = createStore(
persist({
...my state goes here
}, {
allow: ['state attributes here ex. user'],
storage: AsyncStorage
}));
发布于 2022-11-16 17:29:07
在调试和搜索GitHub问题上花费了大量时间之后,我找到了这个解决方案。在这里很有魅力。另外,您需要允许持久化哪个状态变量。
import { action, createStore, persist } from "easy-peasy";
import AsyncStorage from "@react-native-async-storage/async-storage";
const store = createStore(
persist({
...my state goes here
}, {
storage: {
getItem: async function (key){
console.log("GET_ITEM: ", key);
const value = await AsyncStorage.getItem(key);
return JSON.parse(value);
},
setItem: function (key, value){
console.log("SET_ITEM: ", key, value);
AsyncStorage.setItem(key, JSON.stringify(value))
}
},
allow: ['Names of the state variables to be persisted goes here']
})
);https://stackoverflow.com/questions/71502631
复制相似问题