哪里有做这个的好地方?我尝试调用在 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/