[英]how to Modify a child object from you state in the reducer with 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.