DEMO.
const initalState = {
foo: 'bar',
baz: 'pew',
structure: [
['', ''],
['', ''],
],
};
const reducer = (state, action) => {
switch (action.type) {
case 'ADD_INPUT':
return {
...state,
structure: state.structure.map((v1, k1) => {
if (k1 === action.first) {
return v1.map((v2, k2) => {
if (k2 === action.second) {
return action.value;
} else {
return v2;
}
});
} else {
return v1;
}
}),
};
break;
default:
return state;
}
};
const newState = reducer(initalState, {
type: 'ADD_INPUT',
first: 0,
last: 0,
value: 'foo',
});
console.log(initalState);
console.log(newState);