Reputation: 155
I am trying to add a new property to an exercise I want to mark as complete, and I can't get the right shape.
This is the reducer:
case COMPLETE_EXERCISE:
return {
...state,
[action.payload.id]: {
...[action.payload.completedExercise],
complete: true
}
};
I want to add the complete: true
property to the completedExercise
object and to get rid of that 0
index object key so that the Id
prop of the completedExercises
object contains the name
, screenName
, text
AND the complete
props, however the closest I could come up to is to put it next to it:
My current state looks like:
and I want it to look like:
Upvotes: 1
Views: 61
Reputation: 21881
Just don't wrap action.payload.completedExercise
in an array
case COMPLETE_EXERCISE:
return {
...state,
[action.payload.id]: {
...action.payload.completedExercise,
complete: true
}
};
Example:
const foo = { a: 1 };
const bar = {
...foo,
b: 2
};
console.log(bar);
Upvotes: 2