![](/img/trans.png)
[英]react js with redux, my container isn't receiving data after success actions / reducers
[英]ReactJS Redux Persist isn't showing my reducers
由於某些原因-當我console.log(this.props)時,我看不到我的減速器。 每次重新加載應用程序時,都會進行一次清除操作以重置此當前Redux狀態。 我什至無法查看INITIAL_STATE默認值。 以下是我的HOC,其中包含路由器,提供程序和持久性門。 還有reducer(reducers / index.js)和store配置文件(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')
);
存儲/ 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}
減速器/ 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
我需要將以下內容添加到我的createstore
combineReducers({
state: persistedReducer
}),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.