Reactjs 使用startAfter时按降序排列的firestore订单

Reactjs 使用startAfter时按降序排列的firestore订单,reactjs,redux,google-cloud-firestore,pagination,infinite-scroll,Reactjs,Redux,Google Cloud Firestore,Pagination,Infinite Scroll,我这里有一个函数,用于获取集合中的所有文档。 返回的信息将分页,并且仅在用户向下滚动页面时返回下一个文档 export function fetchScreamsFromFirestore(limit, lastDocSnapshot = null) { let screamsRef = db .collection('screams') .orderBy('createdAt') .startAfter(lastDocSnapshot) .limit(lim

我这里有一个函数,用于获取集合中的所有文档。 返回的信息将分页,并且仅在用户向下滚动页面时返回下一个文档

export function fetchScreamsFromFirestore(limit, lastDocSnapshot = null) {
  let screamsRef = db
    .collection('screams')
    .orderBy('createdAt')
    .startAfter(lastDocSnapshot)
    .limit(limit);

  return screamsRef;
}
当我将'desc'参数添加到此函数时,如下所示:

export function fetchScreamsFromFirestore(limit, lastDocSnapshot = null) {
  let screamsRef = db
    .collection('screams')
    .orderBy('createdAt', 'desc')
    .startAfter(lastDocSnapshot)
    .limit(limit);

  return screamsRef;
}

然后它什么也不返回。有没有想过如何解决这个问题?

我来晚了一点,但我想这可能只是一个语法问题

试试看

    export function fetchScreamsFromFirestore(limit, lastDocSnapshot = null) {
  let screamsRef = db
    .collection('screams')
    .orderBy('createdAt', descending: true)
    .startAfter(lastDocSnapshot)
    .limit(limit);

  return screamsRef;
}

请编辑问题,解释什么东西没有按您预期的方式工作。你应该指出你正在处理的数据,并详细说明你采取的步骤。现在,我们无法看到您如何获取和传递lastDocSnapshot,或者查询应该返回什么。