use-firestore-pagination
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

use-firestore-pagination

A react hook for cumulative pagination of a firebase collection. This means that the query maintains a reference to existing documents when loading more documents.

Install

yarn add use-firestore-pagination

Basic usage

import usePagination from "use-firestore-pagination";
import firebase from "firebase/app";
 
function Example() {
  const {
    loading,
    loadingError,
    loadingMore,
    loadingMoreError,
    hasMore,
    items,
    loadMore 
  } = usePagination(
    firebase
      .firestore()
      .collection("recipes")
      .where("userId", "==", 1)
      .orderBy("updatedAt", "desc"),
    {
      limit: 25
    }
  );
 
  return (
    <div>
      {loading && <div>Loading...</div>}
      {items.map(item => (
        <div>{item.id}</div>
      ))}
      {hasMore && !loadingMore && <button onClick={loadMore}>Load more</button>}
    </div>
  );
}

Readme

Keywords

none

Package Sidebar

Install

npm i use-firestore-pagination

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

483 kB

Total Files

21

Last publish

Collaborators

  • bmcmahen