/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进行了更新,
但是没有调用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