Answer the question
In order to leave comments, you need to log in
How can this version of state be rewritten?
I have this option to return one of the cases in the reducer
const el = state.structure[action.id].childIds[0];
if(el) {
if(action.blockId) {
return {
...state,
structure: {
...state.structure,
[el] : {
...state.structure[el],
visibility: true
},
[action.id] : {
...state.structure[action.id],
render : action.render
},
[action.blockId] : {
...state.structure[action.blockId],
block: action.block,
}
}
};
} else {
return {
...state,
structure: {
...state.structure,
[el] : {
...state.structure[el],
visibility: true
},
[action.id] : {
...state.structure[action.id],
render : action.render
},
}
};
}
} else {
if(action.blockId) {
return {
...state,
structure: {
...state.structure,
[action.id] : {
...state.structure[action.id],
render : action.render
},
[action.blockId] : {
...state.structure[action.blockId],
block: action.block,
}
}
};
} else {
return {
...state,
structure: {
...state.structure,
[action.id] : {
...state.structure[action.id],
render : action.render
}
}
};
}
}
Answer the question
In order to leave comments, you need to log in
It looks like you have one action followed by several. Try to break them up - you can use one common action creator:
function removeFromStructure(id) {
return { type: REMOVE_FROM_STRUCTURE, paylodad: id }
}
function doSomething(id) {
return { type: DO_SOMETHING, paylodad: id }
}
function commonAction(structureObject) {
return structureObject.blockId ? removeFromStructure(id) : doSomething(id)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question