react-native - 如何停止多个 Firebase 事件回调(值,快照)
问题描述
我是火力基地的新手。我想在用户单击任何 pushKey 时获取实时数据。当我单击另一个节点时,我也会获得以前的节点数据。我不知道在哪里使用 ref.off('value',listener)。请帮帮我。任何帮助将不胜感激
export const fetchCurrentCircleLocation = pushKey => { return async dispatch => {
让 ref = firebase.database().ref( Circles/${pushKey}/members
);
let listener = await ref.on("value", snapshot => {
// console.log("circleLocation", snapshot.val());
dispatch({
type: FETCH_CURRENT_GROUP_CIRCLE_LOCATION,
payload: snapshot.val()
});
});
}; };
解决方案
尝试使用一次。它只会遍历您的数据库项目一次。您不需要删除侦听器。
ref.once("value", function (snapshot) {
snapshot.forEach((child) => {
console.log(child.val())
});
});
推荐阅读
- postgresql - 如何在选择最大值时选择最大日期值
- php - 在 WooCommerce 商店页面中显示变体数量
- powershell - 空有效载荷。预期的 JSON 内容。Microsoft Graph 和 Powershell
- flutter - Flutter如何在appbar中扩展图像?
- r - 如何使用函数 fit() 预测单个值?
- linux - 在 ubuntu 20.04 上启动 GraphDB 9.5 的问题
- javascript - React Material UI Grid 页脚更改
- javascript - 如何使用 vue-router 在应用程序中正确清除 Vuex 状态?
- java - Android:如何在外部 java 库中启用打印到 android 控制台?
- python - 在第 14 个 Epoch 在 Imagenet 上训练 Resnet50 时出错