My state model is like below
export interface State {
[key: string]: UnitState;
}
So State is holding states of all units with key as unitID. So it should ideally look like this
{ 'ABC': {unitName: 'John', unitOpen: 'true'},
'XYZ': {unitName: 'Peter', unitOpen: 'false'}
}
Now when I want to do some state updates in the reducer how do I do that? I tried something like this but it didn't work. I checked other posts here, but none of them had examples for a key indexed array
case 'UPDATE_UNIT_NAME': {
const stateCopy = Object.assign({}, state);
const name = action.name;
stateCopy[unitId] = { ...stateCopy[unitId], unitName: name};
return {...state, stateCopy};
}