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

243
Views
redux update delete add value to object inside object by id if exist or not

hello I would like to update, delete and add value inside my redux store, my API return object of map for example

carList:{
"bmw" : [
   {
            "id": "C4FC3DC3-4C88-EC11-97A5-B07D6412D8C3",
            "buyDate": "2000-02-07T19:33:02.613+00:00",
            "sellDate": "2022-02-07T19:33:02.613+00:00",
            "carID": "bmw",
            "color": "red"
        },
{
            "id": "C4FC3DC3-4C88-EC11-97A5-B07D6412D8A3",
            "buyDate": "2010-03-07T19:33:02.613+00:00",
            "sellDate": "2019-01-12T19:33:02.613+00:00",
            "carID": "bmw",
            "color": "blue"
        }
],
"Ford" : [
   {
            "id": "C4FC3DC3-4C88-EC11-97A5-B07D6412D8C3",
            "buyDate": "2000-02-07T19:33:02.613+00:00",
            "sellDate": "2022-02-07T19:33:02.613+00:00",
            "carID": "Ford",
            "color": "red"
        },
{
            "id": "C4FC3DC3-4C88-EC11-97A5-B07D6412D8A3",
            "buyDate": "2010-03-07T19:33:02.613+00:00",
            "sellDate": "2019-01-12T19:33:02.613+00:00",
            "carID": "Ford",
            "color": "blue"
        }
]

}

and I dont know how to make cases in reducer for this simple code.

My insert update and delete object looks like

{
            "id": "C4FC3AS3-4C88-EC11-97A5-B07D6412D8A3",
            "buyDate": "2020-03-07T19:33:02.613+00:00",
            "sellDate": "2021-01-12T19:33:02.613+00:00",
            "carID": "Ford",
            "color": "blue"
        }
 case DELETE_CAR:
            return { ...state,
                carList : Object
                    .keys(carList)
                    .filter(key => key !== action.payload.carID)
                    .reduce((obj, key) => { obj[key] = carList[key]; return obj; }, {} ) };


  case ADD_CAR: return {
            ...state,
            carList : state.carList [action.payload.carID]=  [...state.carList [action.payload.carID],action.payload]
        };
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!