我正在尝试将我的不可变状态保留在 localStorage 中。下面是我的减速器 index.js
import { combineReducers } from 'redux';
import posts from './PostReducer';
import polls from './PollReducer';
import categories from './CategoryReducer';
import activeThreads from './ActiveThreadReducer';
export default combineReducers({
posts,
polls,
categories,
activeThreads
})
在我的 persistStore.js 中,我有类似下面的内容。
import immutableTransform from 'redux-persist-transform-immutable'
import { persistStore, autoRehydrate } from 'redux-persist-immutable';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
const config = {
key: 'root',
storage,
};
const loggerMiddleware = createLogger();
const finalCreateStore =
composeWithDevTools(
applyMiddleware(
thunkMiddleware,
loggerMiddleware,
),
autoRehydrate()
);
const reducer = persistReducer(config, reducers)
export const store = createStore(reducer, undefined, finalCreateStore);
export const persistor = persistStore(store, { transforms: [immutableTransform({})] }, () => {
console.log('rehydration complete', store.getState());
return store;
});
在我的主应用程序中,
return (
<Provider store={store}>
<PersistGate
loading={<Loading />}
onBeforeLift={this.onBeforeLift}
persistor={persistor}>
<Router history={browserHistory}
createElement={this.createElementWithActions}>
<Route path="/" component={Main}>
...
</Router>
</PersistGate>
</Provider>
);
我的应用程序返回以下错误。
未捕获的类型错误:persistor.getState is not a function at PersistGate._this.handlePersistorState (react.js:41) at PersistGate.componentDidMount (react.js:55) at ReactCompositeComponent.js:262 at measureLifeCyclePerf (ReactCompositeComponent.js:73) at ReactCompositeComponent.js:261 在 CallbackQueue.notifyAll (CallbackQueue.js:74) 在 ReactReconcileTransaction.close (ReactReconcileTransaction.js:78) 在 ReactReconcileTransaction.closeAll (Transaction.js:207) 在 ReactReconcileTransaction.perform (Transaction.js:154) 在batchedMountComponentIntoNode (ReactMount.js:124)
我在这里和Here阅读了有关 redux-persist 的文档。请问我做错了什么,错误意味着什么?任何帮助将不胜感激