I am trying to remove an object from a nested object items in the redux state. I can only manage to remove the values instead of the actually key. I cannot filter it since it's not an array. I though maybe Object.keys(state.items[or_id]).reduce() might be a option?
The state:
items: {
'b0ad5c5c-5cf4-40b5-9bc9-87f773ba3c06': {
'7e8557dc-9352-4dea-a062-0a1d43371698': {
value: {
id: '7e8557dc-9352-4dea-a062-0a1d43371698',
expires_on: '2020-11-19T14:22:18.182000+00:00'
}
},
'7e8557dc-9352-4dea-a062-0a1d43371692': {
value: {
id: '7e8557dc-9352-4dea-a062-0a1d43371692',
expires_on: '2021-11-19T14:22:18.182000+00:00'
}
}
}
},
The reducer:
if(type === DELETE){
const { or_id, in_id } = payload;
return {
...state,
items: {
...state.items,
[or_id]: {
...state.items[or_id],
[in_id]: {},
},
},
};
}
If I use this method above the key still exists in the state.
items: {
'b0ad5c5c-5cf4-40b5-9bc9-87f773ba3c06': {
'7e8557dc-9352-4dea-a062-0a1d43371698': {},
'7e8557dc-9352-4dea-a062-0a1d43371692': {
value: {
id: '7e8557dc-9352-4dea-a062-0a1d43371692',
expires_on: '2021-11-19T14:22:18.182000+00:00'
}
}
}
Expected result (1 item less):
items: {
'b0ad5c5c-5cf4-40b5-9bc9-87f773ba3c06': {
'7e8557dc-9352-4dea-a062-0a1d43371692': {
value: {
id: '7e8557dc-9352-4dea-a062-0a1d43371692',
expires_on: '2021-11-19T14:22:18.182000+00:00'
}
}
}