1.1.16 • Published 9 months ago

react-firebase-pagination v1.1.16

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

npm version

react-firebase-pagination

A React Hook that makes it easy to paginate Firestore collections. This hook provides cumulative pagination and maintains references to previous documents, so it might not be suitable for large document sets.

Support for Firebase 9

support for Firebase 9 and are backwards incompatible with previous versions of Firebase.

Install

npm install react-firebase-pagination

OR

yarn add react-firebase-pagination

Options

propTypeDefaultdescriptionRequired
queryQuerynullThe query of your Firebase database. e.g. query(collection(db, '[collection]')).
pageSizeNumber10The number of items per page.
pageByPageBooleanfalseWhen this option is True, data is loaded page by page like Google search, and when it's not, it loads data on a single page and appends new data on the bottom of current data like a Facebook feed.
liveUpdateBooleanfalseAdd Firebase snapshot listener to update data live

State

propvaluedescription
loadingBooleanIs true when a page is loading.
dataObjectData Object
getNextFunctionW'll render the next page when called. (Take no arguments)
getPreviousFunctionW'll render the previous page when called. (Take no arguments and work only in pageByPage mode)
hasNextBooleanIt's true when the next page has data.
hasPreviousBooleanIt's true when a previous page has data. (Work only in pageByPage mode)

Data Object Contain

propvaluedescription
docsDocumentsDocument Array.
totalDocsNumberTotal Document count.
totalPagesNumberTotal Page count.
currentPageNumberCurrent Page Number in pageByPage mode or how may time's data load on the current page

Example Use

This is an example of a Firestore.

You can also change query during runtime. Hook will detect new query and start pagination from the beginning. Here is an example of controlling query's orderDirection by React's state:

import usePagination from 'react-firebase-pagination';
import { query, orderBy, collection } from 'firebase/firestore'
import db from './your/database/path';

const mainQuery = query(collection(db, '[collection]'), orderBy('created_timestamp', 'desc'));

const App = () => {
  const { getNext, getPrevious, data, loading } = usePagination({
    pageSize: 10,
    pageByPage: true,
    query: mainQuery,
  })

  if (loading) {
    return <LoadingComponent />
  }

  ...
}
1.1.16

9 months ago

1.1.14

10 months ago

1.1.13

10 months ago

1.1.12

10 months ago

1.1.11

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.98

11 months ago

1.0.97

11 months ago

1.0.96

11 months ago

1.0.95

11 months ago

1.0.94

11 months ago

1.0.93

11 months ago

1.0.92

11 months ago

1.0.91

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago