score:12

Accepted answer

Why not simply:

reducer.js

import {
  ADD_CITY, REMOVE_CITY
} from '../Constants';

const cityReducer = (state = [], action) => {
  switch (action.type) {
    case ADD_CITY:
      return [
        ...state,
        action.city
      ]
    case REMOVE_CITY:
      return state.filter(city => city !== action.city)
    default:
      return state;
  }
}

export default cityReducer;

score:2

Your remove city reducer should look like

case REMOVE_CITY:
  return [
    ...state.filter(city => city !== action.city),
  ]

Otherwise you're adding all the previous items plus the filtered list.


Related Query

More Query from same tag