簡體   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