npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-firebase-pagination

v1.1.16

Published

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.

Downloads

233

Readme

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

| prop | Type | Default | description | Required | | ---------- | --------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | | query | Query | null | The query of your Firebase database. e.g. query(collection(db, '[collection]')). | ✔ | | pageSize | Number | 10 | The number of items per page. | | | pageByPage | Boolean | false | When 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. | | | liveUpdate | Boolean | false | Add Firebase snapshot listener to update data live | |

State

| prop | value | description | | ----------- | ---------- | ----------------------------------------------------------------------------------------------------------- | | loading | Boolean | Is true when a page is loading. | | data | Object | Data Object | | getNext | Function | W'll render the next page when called. (Take no arguments) | | getPrevious | Function | W'll render the previous page when called. (Take no arguments and work only in pageByPage mode) | | hasNext | Boolean | It's true when the next page has data. | | hasPrevious | Boolean | It's true when a previous page has data. (Work only in pageByPage mode) |

Data Object Contain

| prop | value | description | | ----------- | ----------- | -------------------------------------------------------------------------------------------------- | | docs | Documents | Document Array. | | totalDocs | Number | Total Document count. | | totalPages | Number | Total Page count. | | currentPage | Number | Current 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 />
  }

  ...
}