我试图在reducer函数中添加immutable。但是,当来自firebase的数据命中时,我收到错误Uncaught TypeError: currentState.merge is not a function
。
Reducer代码如下(注释代码没有不可变)
import C from '../../constants';
import initialState from '../initialState';
import {Map, List, fromJS} from 'immutable';
const membersInitialState = fromJS(initialState.members);
export default (currentState = membersInitialState, action) => {
let newstate;
switch (action.type) {
case C.RECEIVE_MEMBER_DATA:
/*return Object.assign({}, currentState, {
hasReceivedData: true,
data: action.data
});*/
return currentState.merge({
hasReceivedData: true,
data: action.data
});
//default: return currentState || initialState.members;
}
return currentState;
}
rootReducer如下
import membersReducer from './members';
function rootReducer (state, action){
return {
members: membersReducer(state.members, action)
}
};
export default rootReducer;
答案 0 :(得分:2)
问题是因为store
创建而没有使用不可变对象。
export default createStoreWithMiddleware(rootReducer, fromJS(initialState));
如上所述更新后,现在正在运作。