I have a fairly complex/nested redux store like this:
{
object1
{
array:
[
object[1]: {
id: 1,
replace: ""
}
object[2]: {
id: 2
replace: ""
}
object[3]: {
id: 3,
replace: ""
}
]
}
}
After dispatching an action, I need to insert the action to one of the object[] based on ID. I am currently using the following scripts to update replace within the reducer. However this will change the array to an object due to the curly bracket of object2: {}.
case UPDATE:
return {
...state,
object1: {
...state.object1,
array: {
...state.object1.array,
[action.id]: {
...state.object1.array[action.id],
replace: action.result
}
}
}
};
My render will breaks after that since object2.map is no longer a function after changing to object. How do I workaround this without converting it to an object?
The following will failed with syntax error:
case UPDATE:
return {
...state,
object1: {
...state.object1,
array: [
...state.object1.array,
[action.id]: {
...state.object1.array[action.id],
replace: action.result
}
]
}
};