redux-persist 不会保持 React Native 的状态
redux-persist doesn't keep the state on React Native
我已将 redux-persist
与 Redux 结合使用以保持应用重启之间的状态。目前,在开发版本中,它永远不会保持状态。
我的店铺
const persistConfig = {
key: 'root',
storage: AsyncStorage,
blacklist:['users', 'activity', 'meeting', 'workshop', 'predavanja', 'klizni', 'meetings', 'standing']
}
const allReducers = combineReducers({
darkMode: persistReducer(persistConfig, darkReducer),
users: userReducer,
activity: activity,
meeting: meeting,
workshop: workshop,
predavanja: predavanja,
klizni: klizni,
meetings: meetings,
standing: standing,
});
我一直在记录我想要保留的状态,但它一直返回到默认状态。
有什么理由,你决定将配置中的每个减速器列入黑名单吗?如果您试图保留所有 Redux 状态,则不应定义任何黑名单。此外,我看不到你是如何创建你的 redux 商店的,但它应该看起来像
import { createStore } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
...
const store = createStore(persistReducer(persistConfig, allReducers));
const persistor = persistStore(store);
在你的根组件中,你应该像下面这样注入商店:
import { PersistGate } from 'redux-persist/integration/react';
import { Provider } from 'react-redux';
...
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
.....
</PersistGate>
</Provider>
);
reducer 应类似于以下代码片段:
const persistConfig = {
key: 'root',
storage: AsyncStorage
}
const allReducers = combineReducers({
darkMode: darkReducer,
users: userReducer,
activity: activity,
meeting: meeting,
workshop: workshop,
predavanja: predavanja,
klizni: klizni,
meetings: meetings,
standing: standing,
});
如果您遵循所有这些步骤,您的整个 redux 存储应该被持久化。
我已将 redux-persist
与 Redux 结合使用以保持应用重启之间的状态。目前,在开发版本中,它永远不会保持状态。
我的店铺
const persistConfig = {
key: 'root',
storage: AsyncStorage,
blacklist:['users', 'activity', 'meeting', 'workshop', 'predavanja', 'klizni', 'meetings', 'standing']
}
const allReducers = combineReducers({
darkMode: persistReducer(persistConfig, darkReducer),
users: userReducer,
activity: activity,
meeting: meeting,
workshop: workshop,
predavanja: predavanja,
klizni: klizni,
meetings: meetings,
standing: standing,
});
我一直在记录我想要保留的状态,但它一直返回到默认状态。
有什么理由,你决定将配置中的每个减速器列入黑名单吗?如果您试图保留所有 Redux 状态,则不应定义任何黑名单。此外,我看不到你是如何创建你的 redux 商店的,但它应该看起来像
import { createStore } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
...
const store = createStore(persistReducer(persistConfig, allReducers));
const persistor = persistStore(store);
在你的根组件中,你应该像下面这样注入商店:
import { PersistGate } from 'redux-persist/integration/react';
import { Provider } from 'react-redux';
...
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
.....
</PersistGate>
</Provider>
);
reducer 应类似于以下代码片段:
const persistConfig = {
key: 'root',
storage: AsyncStorage
}
const allReducers = combineReducers({
darkMode: darkReducer,
users: userReducer,
activity: activity,
meeting: meeting,
workshop: workshop,
predavanja: predavanja,
klizni: klizni,
meetings: meetings,
standing: standing,
});
如果您遵循所有这些步骤,您的整个 redux 存储应该被持久化。