繁体   English   中英

如何从Reducer修改Redux存储的状态

[英]How to modify state of a redux store from a reducer

下面是我写的减速器:

function rootReducer(state = rootInitialState, action) {
  const appleState = _.cloneDeep(state.get('apple') || {});
  const orangeState = _.cloneDeep(state.get('orange') || {});

switch(action.type){
case 'appleAction':
  return state.set('apple', action.appleChanges);

case 'orangeAction':
  return state.set('orange', action.orangeChanges);
}

default:
  return state;
}

如果我有一个action.type =='both'并且想要修改状态为'apple'和'orange'的怎么办,那么我将如何返回修改后的状态?

就像是...

case 'both':
return Object.assign({}, state, { apple: action.appleChanges, orange: action.orangeChanges });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM