How can I update multiple properties in my state object with and array of objects?
I have my state in this format:
{
1: { id: 1, values: [ 1, 2] },
2: { id: 2, values: [ 1, 2] }
}
In my reducer I receive the data to update the state in this format:
[
{ id: 1, values: [ 3, 4] },
{ id: 2, values: [ 3, 4 ] }
]
I want to be able to add the values from the objects coming into the reducer to matching object values in the state.
I would like to end up with:
{
1: { id: 1, values: [ 1, 2, 3, 4] },
2: { id: 2, values: [ 1, 2, 3, 4] }
}
I tried to map through this but then it was returning my state into an array. I want to keep my state as an object.