I have a question on how not to add duplicates to my redux store.
It should be straightforward, but for some reason I'm not trying anything to work.
export const eventReducer = (state = [], action) => { switch(action.type) { case "ADD_EVENT": return [...state, action.event].filter(ev => { if(ev.event_id !== action.event.event_id){ return ev; } }); default: return state; } };
action looks something like this:
{ type: "ADD_EVENT", event: { event_id: 1, name: "Chelsea v Arsenal" } }
The problem is that in some cases, the API I'm working with sends identical messages via websocket, which means that two identical events are added to my store.
I took a lot of approaches, but can't figure out how to make this work. I tried a lot of SO answers,
user7597670
source share