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]
};