My redux state looks like this (its synced with Firebase).
{
profile: {
activeUsers: {
Iiva2BGZffNTH84glOLXv8QHVTF2: {
sex: male,
age: 20,
},
PkfMxrN09RN7ygoBMWqm4jheEOx1: {
sex: female,
age: 20,
},
zQiGXvcUGmRSKUdr719621QleUw2: {
sex: male,
age: 25,
}
}
}
}
I want to remove user zQiGXvcUGmRSKUdr719621QleUw2
Heres my action creator
Firebase.database()
.ref('profiles/activeUsers')
.on(
'child_removed',
(snapshot) => {
dispatch(_activeUserChildRemoved(snapshot));
},
(err) => {
console.log(err.toString());
Alert.alert(err);
},
);
};
const _activeUserChildRemoved = snapshot => ({
type: ACTIVE_USER_CHILD_REMOVED,
payload: snapshot,
});
and finally here is my reducer
switch (action.type) {
case ACTIVE_USER_CHILD_REMOVED:
const key4Del = action.payload.key;
return { //what goes here??? };
default:
return state;
}
};
What do i return from reducer in order to remove the user referenced by snapshot.key from redux? Help is much appreciated
Got it!!
case ACTIVE_USER_CHILD_REMOVED:
const key4Del = action.payload.key;
const oldState = state;
delete oldState.activeUsers[key4Del];
return { ...oldState };