首页 > 解决方案 > 关于firestore实时监听器数量的概念问题

问题描述

当我对数据进行分页时,我试图尽量减少 Firestore 侦听器的数量。我使用的是firestore webv9,但这并不重要。我的问题是..

每次我调用这个函数时,我不是在创建一个新的监听器吗?如果是这样,我如何组合或重用侦听器或快照,这样即使我调用此函数 1000 次,我也只有一个侦听器?!

async getPaginatedData_RTL(queryParams: TQueryParams, onChange: Function){

let collectionReference = collection(firestore, queryParams.pathToDataInCollection);

const unsubscribe = onSnapshot(collectionReferenceQuery, (snapshot: QuerySnapshot) => {
  onChange(snapshot);
})

this.unsubscriptions.push(unsubscribe)
}

标签: javascriptreactjsfirebasereact-nativegoogle-cloud-firestore

解决方案


推荐阅读