【发布时间】:2018-06-17 05:35:23
【问题描述】:
在我的 react/redux 应用程序中,我有这个减速器:
import {fromJS} from 'immutable';
import {
CHANGE_USERNAME,
ADD_COUNTER
} from './constants';
// The initial state of the App
const initialState = fromJS({
username: '',
counter:0
});
function homeReducer(state = initialState, action) {
switch (action.type) {
case CHANGE_USERNAME:
// Delete prefixed '@' from the github username
return state
.set('username', action.name.replace(/@/gi, ''));
case ADD_COUNTER:
return state
.set('counter',state.counter+1)
default:
return state;
}
}
export default homeReducer;
目前它命中了减速器,但没有更新计数器的状态。我错过了什么?链接到code
【问题讨论】:
标签: reactjs redux react-boilerplate