如何使用ReactJs对Cloud Firestore数据进行分页

如何使用ReactJs对Cloud Firestore数据进行分页,第1张

如何使用ReactJs对Cloud Firestore数据进行分页

分页可以使用

startAt()

// Get Items.async fetchUsers = () => {  // State.  const {users, usersPerPage} = this.state  // Last Visible.  const lastVisible = users && users.docs[users.docs.length - 1]  // Query.  const query = firestore.collection('Users')    .orderBy('email')    .startAfter(lastVisible)    .limit(usersPerPage)  // Users.  const users = await query.get()  // ..  return this.setState({users})}// Did Mount.componentDidMount() {  this.fetchUsers()}// Did Update.componentDidUpdate(prevProps, prevState) {  const isDifferentPage = this.state.currentPage !== prevState.currentPage  if (isDifferentPage) this.fetchUsers()}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5010400.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存