0

I'm working with redux and I created an action whose reducer should remove the final item of the given state(which is an array) whenever the action is called but I don't know how to return the modified array.

the action:

const removeSelectedItem = ()=> {

    return {
    type: 'removeItem'

  }

}

then, its reducer is to go remove the last item from its state which is an array

const handleSelectedItem = (state= [], { type, payload })=> {
     switch(type){
       case 'addItem' : 
         return [...state, payload]

        case 'removeItem': 
          return [] {// point I'm stuck}
}

}

So please, that's the point where I'm stuck. I don't know how to remove the last item in the array in order to then return the newly modified array. I've tried pop method but that returns the 'popped' element. Please what can I do?

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Liti
  • 21
  • 5

0 Answers0