如何在reducer中获取最后一个状态?
我一直在阅读它,我目前的结构如下:
initialState.js
import cookie from 'react-cookie';
export default {
categories:[],
wishListItems: localStorage.getItem('wlist') || [],
cartData: {},
youMayLikeItems : [],
catalogItems: {'products': []},
categoriesFormatted: []
}
减速机结构:
import * as types from '../actions/actionTypes'
import initialState from './initialState'
export default function sampleReducer(state = initialState.userinfo, action){
switch (action.type) {
case types.SAMPLE_SUCCESS:
return action.abc;
case types.SAMPLE_SUCCESS:
return action.abc;
default:
return state;
}
}
在上面的例子中,我的状态对象永远不会真正获得最后一个状态,但总是initialState
。我真的想摆脱这种行为。
rootReducer:
const rootReducer = combineReducers({
reduxAsyncConnect,
categories,
cookies,
quoteIdAndCustomerId,
wishListItems,
customerInfo,
catalogItems,
wishlistItemAdd,
categoriesFormatted,
loadingBar: loadingBarReducer
//the name here would be exposed and available in mapStateToProps function in react
});
商店:
import {createStore, applyMiddleware} from 'redux';
import rootReducer from '../reducers/index.js';
import thunk from 'redux-thunk';
export default function configureStore(manipulatedState = rootReducer, initialState = initialState) {
return createStore(
manipulatedState,
initialState,
applyMiddleware(thunk, reduxImmutableStateInvariant()),
// promise middleware
applyMiddleware(loadingBarMiddleware())
);
}
如何确保我在我的申请中只发送一次动作,并且永远不会被派遣,因为这是不必要的?