javascript - 使用 Firebase、React-Native、Redux 进行数据库 .on 调用的约定?

标签 javascript firebase react-native firebase-realtime-database redux

哪里有做这个的好地方?我尝试调用在 componentWillMount 内部进行 .on 调用的操作创建者,但是这会在 View 更改之间累积多个相同的监听器。此外,在某些时候,您需要对所有这些监听器调用 .off。处理这个问题的最佳方法是什么?

最佳答案

根据文档:

componentWillMount() is invoked immediately before mounting occurs. [...]. Avoid introducing any side-effects or subscriptions in this method.

我建议在componentDidMount中添加您的听众。正如您所指出的,您并没有取消听众的订阅。为此,您可以使用 componentWillUnmount .

关于javascript - 使用 Firebase、React-Native、Redux 进行数据库 .on 调用的约定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40822935/

相关文章:

javascript - 当只有一个 effect 的 deps 发生变化,而不是其他的时,React useEffect Hook

android - 上传图像,Firebase 显示 "User does not have permission to access this object",即使存储设置是公开的

ios - Firebase 查询关系数据

react-native - React Native - iOS 发布构建失败

ios - React Native 开发模式应用程序不会回退到物理设备 (ios) 上的离线包

javascript - 在 index.html 之外访问 Cordova navigator.camera 插件未定义

javascript - 使用 php 与 Ajax 实现响应式 UI

javascript - Bootstrap 4 Modal 由 ajax 调用打开 - 关闭按钮不起作用

firebase - flutter/火力基地 : Admin features in-app or cloud functions?

javascript - 颜色不是从 Prop 渲染的