更新一组文档而不每次都触发 onSnapshot 侦听器

时间:2021-03-30 07:07:04

标签: reactjs firebase

我想在用户的通知上放置一个侦听器,并且每次我想将 show 属性设置为 (true),但问题是每次更新时 onSnapshot 侦听器都会被触发并执行一些问题。 这是我的代码:

db.collection("members")
   .doc(loggedUser.uid)
   .collection("notifications")
   .onSnapshot(snapshot => {
          const unShowedNoti = snapshot.docs
                .map(doc => ({ body: doc.data(), ref: doc.ref }))
                .filter(doc => !doc.body.show)

          unShowedNoti.forEach(alert => {
               // fire an alert
          })

          // update show to true
          unShowedNoti.forEach(alert => {
               // update show alert
          })
})

0 个答案:

没有答案