如何在redux减速器中更新二维数组中的值?

abh*_*rel 6 arrays redux

(i, j)我正在尝试使用 redux 减速器中的扩展运算符来更新 2D 数组中索引处的值。我的减速机看起来像:

export default (state, action) => {
switch(action.type) {
 case INSERT:
   return {
    ...state,
    myArray: [
     ...state.myArray.slice(0, action.i),
     ...state.myArray[action.i] : [
         ...state.myArray[action.i].slice(0, action.j),
         action.newValue,
         ...state.myArray[action.i].slice(action.j),
     ]
     ...state.myArray.slice(action.i),
    ]
  },
};
Run Code Online (Sandbox Code Playgroud)

我的数组看起来像:

let my Array = [ [1,2,5],[5,8,9],[2,6,9]]
Run Code Online (Sandbox Code Playgroud)

如何(i, j)使用 redux 不可变更新模式更新索引处的新值?

Wal*_*mar 3

或者map根本不使用,只使用扩展运算符和动态密钥:

let arr = [
  [1, 2, 5],
  [5, 8, 9],
  [2, 6, 9]
];

const newValue = 6;
const i = 1;
const j = 2;

let myArr = Object.assign([...arr], {
  [i]: Object.assign([...arr[i]], {
    [j]: newValue
  })
})

console.log(myArr);
Run Code Online (Sandbox Code Playgroud)