好吧所以我在componentDidMount中从Firestore获取数据但是如果我更改组件它正在获取数据我得到错误说:
警告:无法在卸载的组件上调用setState(或forceUpdate)。这是一个无操作,但它表示应用程序中存在内存泄漏。要修复,请取消componentWillUnmount方法中的所有订阅和异步任务。
在Firebase实时数据库中,我们调用ref.off()
来停止查询。
想知道如何在Firestore中做到这一点
componentDidMount() {
Users.get().then(({ docs }) => {
const users = docs.map(user => user.data());
this.setState({ users });
});
}
componentWillUnmount(){
}
由于Get
不是实时方法,因此无法在componentWillUnmont上停止它,因此在卸载组件后不应调用它。