我遇到一个问题,我在“主页”屏幕上将侦听器附加到收藏集:
componentWillMount() {
this.ref = firebase.firestore().collection('users').doc(this.state.user.uid).collection('items');
}
componentDidMount() {
this.unsubscribe = this.ref.onSnapshot(this.onCollectionUpdate);
}
现在我有另一个页面,可以在其中更改firebase用户,基本上是将匿名用户迁移到现有的Google帐户-该页面称为“ AddAccount”
我的问题是,当我删除匿名帐户并使用现有的Google帐户登录以还原该帐户的数据时,“主页”屏幕上的侦听器仍在侦听旧的匿名帐户集合,并且由于该帐户现在已删除。
在“ AddAccount”页面上执行数据迁移时,是否可以全局访问侦听器并打开/关闭它们?