All Projects → bmcmahen → firestore-pagination-hook

bmcmahen / firestore-pagination-hook

Licence: other
Cumulative pagination for firebase firestore collections with React hooks

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

firestore-pagination-hook

Hooks for managing cumulative pagination for firestore collections. This means that references to existing entries are maintained as you load additional ones.

Install

yarn add firestore-pagination-hook

Example

import usePagination from "firestore-pagination-hook";
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>
  );
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].