【发布时间】:2018-09-08 17:48:13
【问题描述】:
我正在尝试使用提要在 react-native 上做一个应用程序。在我的主屏幕上,我去获取数据:
fetchData() {
firebase.database().ref(`/posts/${group}`).on('value', async snapshot => {...}
}
例如,当我想点赞该帖子的评论时,我首先使用不同的查询将数据推送到 Firebase,例如:
export const likeComment = (...) => {
firebase.database().ref(`/posts/${group}/${post}`).update
({
updatedAt: firebase.database.ServerValue.TIMESTAMP
});
firebase.database().ref(`/posts/${group}/${post}/lastComments`).set(...);
但我意识到我的第一个函数 fetchData 被调用了 3 次。 然后我将我的查询分组为:
let updates = {}
updates[`/posts/${group}/${post}/lastComments`] = {...};
updates[`/posts/${group}/${post}`] = { ... };
firebase.database().ref().update(updates);
然后,fetchData 仍然被调用了 2 次。
我想知道这是否是最好的方法,为什么我的函数 fetchData 仍然被调用了两次。 感谢您的帮助
【问题讨论】:
标签: firebase react-native