希望修改state.notificatinBar.open
const initialState = {
notificationBar: {
open: false,
},
};
方法一:使用Object.assign()
export default function (state = initialState, action) {
switch (action.type) {
case actions.LAYOUT_NOTIFICATIONBAR_OPEN:
return Object.assign({}, state, {
// TODO: Find a cleaner way to do this!
notificationBar: Object.assign({}, state.notificationBar, {
open: true,
}),
});
default:
return state;
}
}
方法二:使用ES6的三点语法
export default function (state = initialState, action) {
switch (action.type) {
case actions.LAYOUT_NOTIFICATIONBAR_OPEN:
return {
...state,
notificationBar: {
...state.notificationBar,
open: true,
},
};
default:
return state;
}
}