I am building a simple application with reactjs, redux; The database like this
const initialState = [
{
title: "List 1",
id: 0,
cards: [
{
id: 0,
text: "Task 1",
},
{
id: 1,
text: "Task 2",
},
],
},
{
title: "List 2",
id: 1,
cards: [
{
id: 0,
text: "Task 3",
},
{
id: 1,
text: "Task 4",
},
],
},
];
The app has many lists. In many list has many cards, I want delete a card in a list So in my listReducer.js. I created a delete reducer to delete a task like this.
case CONSTANTS.DELETE_CARD: {
const { listId, id } = action.payload;
return state.map((list) => {
if (list.id === listId) {
return {
...list,
cards: list.cards.filter((card) => card.id !== id),
};
}
return list;
});
}
But It not working correctly. What I am doing wrong?