gpt4 book ai didi

react-native - redux-persist/createPersistoid : error serializing state TypeError: Converting circular structure to JSON

转载 作者:行者123 更新时间:2023-12-04 01:02:49 28 4
gpt4 key购买 nike

我正在尝试将 redux-persist 集成到我的 react-native 项目中。目的是在应用程序重新启动之间保留 redux 存储的数据,以便用户无需在每次启动应用程序时登录。另外,我想将以前查看的数据存储在本地存储上,以避免每次重新启动应用程序时重新查询所有数据。

我按照下面的代码添加了 redux 持久支持:

import { AsyncStorage } from 'react-native';
import { createStore, applyMiddleware } from 'redux';
//import { createLogger } from 'redux-logger';
import { persistStore, persistReducer } from 'redux-persist';
import rootReducer from '../reducers/index';
import ReduxThunk from 'redux-thunk';
import { createTransform } from 'redux-persist';
import JSOG from 'jsog';

export const JSOGTransform = createTransform(
(inboundState, key) => JSOG.encode(inboundState),
(outboundState, key) => JSOG.decode(outboundState),
)

const persistConfig = {
// Root
key: 'root',
// Storage Method (React Native)
storage: AsyncStorage,
//transforms: [JSOGTransform]
// Whitelist (Save Specific Reducers)
// whitelist: [
// 'authReducer',
// ],
// // Blacklist (Don't Save Specific Reducers)
// blacklist: [
// 'counterReducer',
// ],
};

// Middleware: Redux Persist Persisted Reducer
const persistedReducer = persistReducer(persistConfig, rootReducer);

// Redux: Store
const store = createStore(
persistedReducer,
applyMiddleware(ReduxThunk),
);

// Middleware: Redux Persist Persister
let persistor = persistStore(store);
// Exports
export {
store,
persistor,
};

如果我不添加 jsog 并使用 transforms: [JSOGTransform]在persistConfig 行中,我收到此错误:

redux-persist/createPersistoid: error serializing state TypeError: Converting circular structure to JSON



如果我取消对 persistConfig 中的“transforms”行的注释(按照此处的建议: https://github.com/rt2zz/redux-persist/issues/735),则会收到此错误:

Exception in HostObject::set: < unknown >



我只是坚持从 返回的“用户”对象消防店我的 redux-store 中的数据库。如果没有 redux-persist,就没有问题,但是添加了 persist 我遇到了这个问题。

成功登录firestore(使用密码/电子邮件身份验证)后返回的用户对象中会存在什么类型的循环问题?

为什么 JSOG 不能按照上面链接中的建议工作?我如何解决这个问题的任何替代方法?

附言不仅是从 firestore 返回的用户导致了这些错误,而且从 firestore 返回的任何数据似乎都无法持久化。

我感谢任何帮助!
干杯...

最佳答案

我想我解决了这个问题。我安装的不是 JSOG flatted并用于我的 redux-persist 转换。

工作转换和persistConfig 看起来像这样:

export const transformCircular = createTransform(
(inboundState, key) => Flatted.stringify(inboundState),
(outboundState, key) => Flatted.parse(outboundState),
)

const persistConfig = {
key: 'root',
storage: AsyncStorage,
stateReconciler: autoMergeLevel2,
transforms: [transformCircular]
};

关于react-native - redux-persist/createPersistoid : error serializing state TypeError: Converting circular structure to JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57906696/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com