I am puzzled.
const oldPosts = state.items; // -> [{id: 12, ... }, {id: 13, ... }]
const newPosts = action.posts // -> [{id: 12, ...}];
// what I want to have is [{id: 12, ... }, {id: 13, ... }] / "merged"
const iWantMerged = ...??
So my approach would be something like this
const merged = [...newPosts, ...oldPosts];
// -> [{id: 13, ... }, {id: 12, ... }, {id: 13, ... }]
// and then remove the duplicated items.
So two questions:
- Is this the right approach or is there better approach IN ES6?
- If no: what is the best way to remove the duplicates?