Answer the question
In order to leave comments, you need to log in
Is it correct to update state in redux this way?
There is the following state:
const state = {
desks: [
{
id: 1,
name: 'Что нужно сделать',
cards: [
{
id: 1,
name: 'Lol kek cheburek'
}
]
}
]
};
function deskReducer(state = [], action) {
switch(action.type) {
case 'ADD_CARD':
let desks = state.slice();
let currentDesk = desks.filter( (item) => item.id === action.id )[0];
currentDesk.cards.push({
id: currentDesk.cards.length + 1,
name: action.name
});
return desks;
default:
return state;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question