我的 redux 状态看起来像这样(它与 Firebase 同步)。
{
profile: {
activeUsers: {
Iiva2BGZffNTH84glOLXv8QHVTF2: {
sex: male,
age: 20,
},
PkfMxrN09RN7ygoBMWqm4jheEOx1: {
sex: female,
age: 20,
},
zQiGXvcUGmRSKUdr719621QleUw2: {
sex: male,
age: 25,
}
}
}
}
我想删除用户 zQiGXvcUGmRSKUdr719621QleUw2
这是我的动作创造者
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,
});
最后这是我的减速器
switch (action.type) {
case ACTIVE_USER_CHILD_REMOVED:
const key4Del = action.payload.key;
return { //what goes here??? };
default:
return state;
}
};
为了从redux中删除snapshot.key引用的用户,我从reducer返回什么?非常感谢帮助