Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Reducer not deleting items from the state

I am unable to delete items from the redux state. I have created a pizza app and I am trying to delete items from the cart. I have successfully implemented increased quantity or deleting all items in cart functions. However, I am unable to implement a delete a particular item function. My button on the front end are working properly and passing ID to deletePizza function given below

Here is my reducer

export const cartReducer = (state = [], action) => {

    switch (action.type) {
        //Required by next-js-reducer library
        case HYDRATE:
            return { ...state, ...action.id };

        //Removes all pizza from the cart
        case 'DELETE_ALL':
            return []

        //Add pizza to cart, if exists increment the pizza
        case 'ADD_PIZZA':
            //If pizza is already in the cart
            const findPizzaIfAdded = state.find(pizza => pizza.id === action.id);
            if (findPizzaIfAdded !== undefined) {
                const modifiedQuantity = {
                    ...findPizzaIfAdded,
                    quantity: findPizzaIfAdded.quantity + 1
                }
                return state.map(pizza => pizza.id === action.id ? modifiedQuantity : pizza);
            }

            const newPizza = {
                id: action.id,
                quantity: 1
            }

            return [
                ...state,
                newPizza
            ]

        //I am facing problem here
        case 'DELETE_PIZZA':
            return state.filter(pizza => pizza.id !== action.id);

        default:
            return state
    }
}

// I am using this funcntion to call deletion of pizza, I tried testing if particular function is working. It is successfully working and passing the id
export const deletePizza = id => {
    return {
        type: 'DELETE_PIZZA',
        id
    }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!