0

/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}

I definitely check state of redux store is updated by Redux-dev-tool and redux-logger,

enter image description here

enter image description here

but mapStateToProps is not being called.


PresentationalComponent.js

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

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

When the page is rendered first time, as you can see mapStateToProps, "inside category name", state.categoryName is shown in console and presentational component correctly get props.categoryName from initialState of redux store. However, why the change in redux store didn't trigger mapStateToProps??

Is this problem related with immutability of state of redux store?


Container.js

...
const mapDispatchToProps = (dispatch) => ({

    onModifyCategoryName: (categoryNewName) => {
        dispatch(actions.modifyCategoryName(categoryNewName))
    }
})

export default connect(null, mapDispatchToProps)(ModifyCategoryNameModal)
...
dance2die
  • 35,807
  • 39
  • 131
  • 194
1Sun
  • 2,305
  • 5
  • 14
  • 21

0 Answers0