score:5

Accepted answer

Array.prototype.filter does not mutate the array, it creates a new one.

So this:

draftState.burgers.filter(el => el.id !== action.payload)

is not actually changing draftState.burgers. But this will:

produce(state, (draftState) => {
  draftState.burgers = draftState.burgers.filter(el => el.id !== action.payload)
})

Related Query

More Query from same tag