I have the current data structure in my redux state
const state = {
chats: {
id: "idhere",
messages: [
{
obj: "here"
},
{
obj: "here"
},
]
}
}
I want to append a result return from my action created to the end of the messages array without mutating it. I understand how I would achieve this if the messages array was a direct child of the state but as it's nested it has completely thrown me.
This is how I've got it at the moment but I'm using push, and it doesn't 'feel' right.
case GET_CHAT_MESSAGES:
return { ...state, chats: { ...state.chats[action.id].messages: ...state.chats.[action.id].messages, action.payload }}
Thanks