In reducers,we always use Object.assign({},state,newState)
to save a state. But assign()
doesn't support deepcopy,because this method only copy a reference of multi-level object. This is my code in program.
const menuListState={
menuList: {},
menuListLoading:false
}
function getMenuList(state=menuListState,action=defaultAction){
switch(action.type){
//menuList begin
case actions.GET_MENULIST_SUCCESS:
return Object.assign({},state,{
menuList:action.data,
menuListLoading:false
});
default:
return state;
}
}
The property menuList
is a multi-level Object. And when action.data
changes, will state.menuList
be changed immediately before the method assign()
work?