reactjs - 类型错误:unsubFirebaseSnapShot01 不是函数
问题描述
我正在使用 React 构建一个 Web 应用程序。
在主屏幕上,我有以下代码。运行应用程序时,它会抛出TypeError: unsubFirebaseSnapShot01 is not a function。
这些是对这些函数的唯一引用index.js
:
let unsubFirebaseSnapShot01;
let unsubFirebaseSnapShot02;
let unsubFirebaseSnapShot03;
...
class Home extends Component {
...
componentWillUnmount() {
this.mounted = false;
unsubFirebaseSnapShot01();
unsubFirebaseSnapShot02();
unsubFirebaseSnapShot03();
}
checkAll = () => {
this.checkMeetingsSetByMe();
this.checkMeetingsSetForMe();
this.checkNotifications();
};
checkMeetingsSetByMe = () => {
if (!this.mounted) return;
const {
user: { uid },
} = this.props;
this.setState({ screenLoading: true });
unsubFirebaseSnapShot01 = Meetings.where('setBy', '==', uid).onSnapshot(
({ docs }) => {
// setting all the meetingsSetByMe in one place
const meetingsSetByMe = docs.map(item => item.data());
if (this.mounted);
this.setState({ meetingsSetByMe, screenLoading: false });
},
);
};
checkMeetingsSetForMe = () => {
if (!this.mounted) return;
const {
user: { uid },
} = this.props;
this.setState({ screenLoading: true });
unsubFirebaseSnapShot02 = Meetings.where('setWith', '==', uid).onSnapshot(
({ docs }) => {
// setting all the meetingsSetForMe in one place
const meetingsSetForMe = docs.map(item => item.data());
if (this.mounted);
this.setState({ meetingsSetForMe, screenLoading: false });
},
);
};
checkNotifications = () => {
if (!this.mounted) return;
const {
user: { uid },
} = this.props;
this.setState({ screenLoading: true });
unsubFirebaseSnapShot03 = Meetings.where('status', '==', 'unseen')
.where('setWith', '==', uid)
.onSnapshot(({ docs }) => {
const notifications = docs.map(item => item.data());
if (this.mounted);
this.setState({ notifications, screenLoading: false });
});
};
仔细检查任何错别字,但看不到我的错误。有什么帮助吗?
解决方案
推荐阅读
- google-cloud-platform - 一个实例或每个数据库的表限制为 10,000 个
- excel - 如何生成 100 个随机变量(列),每列有 1000 行随机生成的数字?
- javascript - 错误:无法读取未定义的属性“PureComponent”
- php - PHP 作曲家,不要在更新时丢失包代码更改
- docker - docker tail -n 没有显示正确的编号。行数
- javascript - git api 在执行 axios 调用时返回 401 未经授权的错误,但 curl 返回 200
- github - 如何检索拉取请求编号
- python - 连接字典的 n 值以在 Python 中为列表创建新值
- string - Teradata SQL - 行/记录之间的字符串相似性
- java - java 1.3 到 1.4 文本资源本地元素(资源包)