“如何结合”;其中;及;starAt";及;“限制”;在一个查询中[FIREBASE、REACT NATIVE、REDUX]

“如何结合”;其中;及;starAt";及;“限制”;在一个查询中[FIREBASE、REACT NATIVE、REDUX],firebase,react-native,google-cloud-firestore,react-redux,Firebase,React Native,Google Cloud Firestore,React Redux,我正在尝试构建一个无限卷轴,这些是我正在使用的函数,我有两个函数正在使用FetchDistributors()和FetchMoreDistributors(),第一个函数的工作方式与预期的一样,但第二个函数的查询在OnSnapshot中返回null: 初始提取(工作正常) 在这里,我遇到了LoadMore函数的问题,查询res返回null,我不知道我做错了什么 async fetchMoreDistrubutors(arg,state){ try {

我正在尝试构建一个无限卷轴,这些是我正在使用的函数,我有两个函数正在使用
FetchDistributors()
FetchMoreDistributors()
,第一个函数的工作方式与预期的一样,但第二个函数的查询在OnSnapshot中返回null: 初始提取(工作正常)

在这里,我遇到了
LoadMore
函数的问题,查询res返回null,我不知道我做错了什么

async fetchMoreDistrubutors(arg,state){
            try {
                const fetch_limit = state.distrubutor.fetch_limit
                const last_visible = state.distrubutor.last_visible

                console.log({last_visible})
                console.log({fetch_limit})

                const moreDstrubutorsResponse= await firestore()
                                        .collection('users')
                                        .where('type','==','DISTRUBUTOR')
                                        .orderBy('id',"desc")
                                        .startAt(last_visible)
                                        .limit(fetch_limit)
               
                moreDstrubutorsResponse.onSnapshot(res=>{
                    if(res == undefined) return 
                    console.log(res)
                    if(res.docs.length)
                    {
                        const PrevDistrubtors =  state.distrubutor.distrubutors
                        const newDistrubtors  = res.docs.map(doc=>doc.data())
                        dispatch.distrubutor.fetcheddistrubutors({
                            distrubutors : [...PrevDistrubtors,...newDistrubtors],
                            last_visible : res.docs[res.docs.length -1].id
                        })
                    }
                })
            } catch (error) {
                console.log(error)
            }
            
}

第二个查询包括
.orderBy('id',“desc”)
,而第一个查询没有。它们不是相同的查询,并且顺序也不相同。

您的第二个查询包括
.orderBy('id',“desc”)
,而第一个查询没有。它们不是同一个查询,顺序也不一样。

但这是必要的,否则我会出错,重点不是从第二个查询中删除它;重点是要将它添加到第一个,但这是必要的,否则我会得到一个错误,重点不是要将它从第二个删除;关键是要将其添加到第一个
async fetchMoreDistrubutors(arg,state){
            try {
                const fetch_limit = state.distrubutor.fetch_limit
                const last_visible = state.distrubutor.last_visible

                console.log({last_visible})
                console.log({fetch_limit})

                const moreDstrubutorsResponse= await firestore()
                                        .collection('users')
                                        .where('type','==','DISTRUBUTOR')
                                        .orderBy('id',"desc")
                                        .startAt(last_visible)
                                        .limit(fetch_limit)
               
                moreDstrubutorsResponse.onSnapshot(res=>{
                    if(res == undefined) return 
                    console.log(res)
                    if(res.docs.length)
                    {
                        const PrevDistrubtors =  state.distrubutor.distrubutors
                        const newDistrubtors  = res.docs.map(doc=>doc.data())
                        dispatch.distrubutor.fetcheddistrubutors({
                            distrubutors : [...PrevDistrubtors,...newDistrubtors],
                            last_visible : res.docs[res.docs.length -1].id
                        })
                    }
                })
            } catch (error) {
                console.log(error)
            }
            
}