维持redux存储状态不变的最好方法是?

时间:2018-09-29 09:12:39

标签: reactjs redux react-redux redux-thunk

/reducers/index.js

import * as types from '../actions/ActionTypes';

var initialState = {
    categoryName: 'default name redux'
};



function re_modifyCategoryName(state=initialState, action) {
    switch(action.type) {
        case types.MODIFY_CATEGORY_NAME :
            return Object.assign({}, state, {
                categoryName: action.categoryNewName
            });

        default:
            return state;

    }
}

export {re_modifyCategoryName}

我肯定检查了state中的redux store是否已由Redux-dev-tool和redux-logger进行了更新,

enter image description here

enter image description here

但是没有调用mapStateToProps


PresentationalComponent.js

... 
const mapStateToProps = (state) => {
    console.log("inside category name", state.categoryName);
    return {categoryName: state.categoryName}
};

export default connect(mapStateToProps)(AnswerEachCategory);
...

首次呈现页面时,如您所见mapStateToProps"inside category name", state.categoryName显示在console中,并且presentational component正确地从{{ props.categoryName中的1}}。但是,为什么initialState中的更改没有触发redux store

这个问题与redux存储的redux store的不变性有关吗?


Container.js

mapStateToProps

0 个答案:

没有答案