由于某些原因-当我console.log(this.props)时,我看不到我的减速器。每次重新加载应用程序时,都会进行一次清除操作以重置此当前Redux状态。我什至无法查看INITIAL_STATE默认值。以下是我的HOC,其中包含路由器,提供程序和持久性门。还有reducer(reducers / index.js)和商店配置文件(store / index.js)
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import {store, persistor} from './store/index';
import { PersistGate } from 'redux-persist/integration/react';
import App from './App';
import './i18n';
persistor.purge()
console.log("purged")
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App/>
</PersistGate>
</Provider>,
document.getElementById('app')
);
store / index.js
import { createStore, applyMiddleware } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web and AsyncStorage for react-native
import rootReducer from '../reducers/index'
const persistConfig = {
key: 'primary',
storage,
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
const middleware = applyMiddleware()
const store = createStore(
persistedReducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
middleware
)
const persistor = persistStore(store)
export {store, persistor}
reducers / index.js
import storage from 'redux-persist/lib/storage';
export const SETJWT = 'auth/login/setJWT'
let INITAL_STATE = {
JWT: 'testJWT',
currentUser: null,
isLoggingIn: false
}
const rootReducer = (state = INITAL_STATE, action) => {
switch(action.type){
case SETJWT:
return {...state, JWT: action.payload};
default:
return state;
}
}
export default rootReducer
答案 0 :(得分:0)
我需要将以下内容添加到我的createstore
combineReducers({
state: persistedReducer
}),