首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能持之以恒地使用简单易感的反应

不能持之以恒地使用简单易感的反应
EN

Stack Overflow用户
提问于 2022-03-16 18:35:47
回答 2查看 238关注 0票数 5

当将AsyncStorage作为存储引擎传递时,我得到以下错误:

代码语言:javascript
复制
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]

这是我的商店声明:

代码语言:javascript
复制
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
    })
);
EN

回答 2

Stack Overflow用户

发布于 2022-03-18 22:37:12

尝试添加“允许”属性

代码语言:javascript
复制
const store = createStore(
persist({
    ...my state goes here
}, {
    allow: ['state attributes here ex. user'],
    storage: AsyncStorage
})

);

票数 0
EN

Stack Overflow用户

发布于 2022-11-16 17:29:07

在调试和搜索GitHub问题上花费了大量时间之后,我找到了这个解决方案。在这里很有魅力。另外,您需要允许持久化哪个状态变量。

代码语言:javascript
复制
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']
    })
);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71502631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档