I have the groups
and members
object with the following structure in the redux state:
groups :{
'1683': {
id: 1683,
members: [
'1',
'2'
],
},
'1900': {...}
}
members: {
'1': {
name: 'user1'
},
'2': {
name:'user2'
}
}
I have the following code in the reducer to remove a member from groups. The first part where I update the members
error inside the group
is working fine. But, the code where I want to remove the targeted member from the members
object itself is not working. I tried splice
but it is not working since members
is not an array. I wonder how I can remove the member based on the key-id match. Any suggestions?
case REMOVE_STUDENT_SUCCESS:
return {
...state,
groups: {
...state.groups,
[action.payload.groupId]: {
...state.groups[action.payload.groupId],
members: state.groups[action.payload.groupId].members.filter(id => id !== action.payload.studentId)
}
},
//NOT WORKING
//members: state.members.splice(action.payload.studentId, 1)
};