问题描述
redux-persist 结合 immutable 报错
问题出现的环境背景及自己尝试过哪些方法
相关代码
request.js
import { fromJS } from 'immutable'
import * as actionTypes from '../actionTypes/request'
const initialState = fromJS({
loadCount: 0
})
/* eslint-disable indent */
export default function (state = initialState, action) {
switch (action.type) {
case actionTypes.LOAD_COUNT:
return state.set('loadCount', action.status.loadCount)
default:
return state
}
}
reducers/index
import { combineReducers } from 'redux-immutable'
import welcome from './welcome'
import request from './request'
const reducer = combineReducers({
welcome,
request
})
export default reducer
store.js
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import { persistStore, persistReducer } from 'redux-persist';
import immutableTransform from 'redux-persist-transform-immutable'
import storage from 'redux-persist/lib/storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
import reducer from './reducers/index'
const persistConfig = {
transforms: [immutableTransform()],
key: 'root',
storage: storage,
stateReconciler: autoMergeLevel2// 查看 'Merge Process' 部分的具体情况
};
const persistedReducer = persistReducer(persistConfig, reducer)
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const middlewares = composeEnhancers(applyMiddleware(thunk));
export const store = createStore(persistedReducer, middlewares);
export const persistor = persistStore(store)
index.js
import { PersistGate } from 'redux-persist/integration/react'
import { Provider } from 'react-redux'
import { store, persistor } from './redux/store'
import LoadingComponent from 'cpt/loading'
import 'normalize.css'
import 'styles/index.scss'
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null}
persistor={persistor}
>
<App />
</PersistGate>
</Provider>
, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
你期待的结果是什么?实际看到的错误信息又是什么?
redux-persist-transform-immutable 感觉没起作用
看我的文章:React项目集成Immutable.js