I have an object gambits
like this
gambits: {
0: {top: 40, left: 231, title: "Card G_0"}
1: {top: 110, left: 134, title: "Card G_1"}
2: {top: 46, left: 109, title: "Card G_2"}
3: {top: 75, left: 212, title: "Card G_3"}
4: {top: 81, left: 139, title: "Card G_4"}
5: {top: 64, left: 267, title: "Card G_5"}
6: {top: 77, left: 109, title: "Card G_6"}
}
I have a functions which call the useReducer
Context
via dispatch
.
const moveGambitDest = (id, left, top) => {
return dispatch({ type: MOVE_GAMBIT_TO_DEST, left, top, id });
};
Inside the reducer i want to update the left
and top
value passed via dispatch
.
export default (state, action) => {
switch (action.type) {
case MOVE_GAMBIT_TO_DEST:
return {
...state,
gambits: { ...state.gambits } // how to mutate the object ?
};
default:
return state;
}
- I do i mutate the
object gambits
inside the above reducer ? . - How do i pass multiple values as payload (id, top ,left) please check my
moveGambitDest
function
Thanks.