我正在开发一个应用程序,如果用户有新订单,则必须通知该应用程序。我还没有找到计算新通知数量的解决方案

每次发送新命令时,orders.map()都会呈现它。例如,我用this.state.orders.length测试过,这里有4个通知,库鲁德已经发送了4个订单
componentWillReceiveProps(nextProps, nextState) {
if (this.state.ordersLength!= nextState.ordersLength) {
//how can i do is this is true
}
}我没有找到解决方案,有什么建议吗?
发布于 2019-12-10 16:22:49
你可以拥有这样的东西:
const notificationsNumber = notifications.filter(p => !p.seen).length;因此,我们假设您在notifications数组中有seen属性,您可以在其中定义是否看到它。
我们只过滤那些我们还没有见过的,并得到计数。
发布于 2019-12-10 17:45:31
您的后台是否会在您检查通知后维护一些通知状态?您的后台需要维护一些密钥,比如单个通知的readStatus,以便您可以根据状态进行过滤。
let unreadNotifications=this.state.orders.filter(each=>!each.readStatus)
如果没有密钥,你就不能这么做。
https://stackoverflow.com/questions/59262838
复制相似问题