DEV Community

Discussion on: Destructuring Assignment in ES6- Arrays

Collapse
 
deepankar14693 profile image
deepankar14693 • Edited

Very nicely explained. Can you tell what is happening in below code :

case Actions.AC_UPDATE_TASK:
item = action.payload.item;
props = action.payload.props;
item.start = props.start ? props.start : item.start;
item.end = props.end ? props.end : item.end;
item.name = props.name ? props.name : item.name;
return {
data: [...state.data],
links: [...state.links],
selectedItem: state.selectedItem
};

Here item and props are coming as parameter,item is present there in data array. After manipulating item from props this item needs to be updated in data array but here its not updated in data array after manipulating it. But after destructuring syntax I can see the updated item in data array. How is this possible?