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-count

v0.2.4

Published

React counter component with Firebase integration

Downloads

119

Readme

react-count

Real-time counter button React component baked by Firebase.

See demo here.

Use cases

This component can we useful in the following cases:

  • follow/unfollow button with the showing number of followers
  • like/unlike button with the showing number of likes
  • page views counter
  • counter for the users currently online
  • generic read-only counters hooked up to any numeric data from your Firebase

Install

If you use webpack just install react-count module

  npm install react-count

and require it anywhere in your react app:

  var Count = require('react-count');

or you can use additional more specific components like:

  var OnlineCount = require('react-count').OnlineCount;
  var ViewCount = require('react-count').ViewCount;

Demo

You can see online demo here or you can open examples/index.html in your browser locally. See examples\App.js to understand how this component can be used in your React applications.

Customization

ViewCount has 4 properties:

  • firebaseHost - required property where you specify Firebase host. E.x. https://counter-button.firebaseio.com/
  • firebaseResourceId - required property where unique counter id. E.x. article-1-counter
  • className - CSS classname that will be assigned to the component. This way you'd be able to overwrite styles Optional.
  • counterText - text that will be shown near the counter number

OnlineCount has 4 properties:

  • firebaseHost - required property where you specify Firebase host. E.x. https://counter-button.firebaseio.com/
  • firebaseResourceId - required property where unique counter id. E.x. article-1-counter
  • className - CSS classname that will be assigned to the component. This way you'd be able to overwrite styles Optional.
  • counterText - text that will be shown near the counter number

Count has following properties:

  • firebaseHost - required property where you specify Firebase host. E.x. https://counter-button.firebaseio.com/
  • firebaseResourceId - required property where unique counter id. E.x. article-1-counter
  • className - CSS classname that will be assigned to the component. This way you'd be able to overwrite styles Optional.
  • counterText - text that will be shown near the counter number.
  • allowMultiple - boolean flag that enables increasing counter multiple times by the single user. Default is false.
  • isViewCounter - boolean flag that tells component to increase automatically on each view. Default is false.
  • isOnlineCounter - boolean flag that tells component to increase automatically on each user online. Default is false.
  • isUndoable - boolean flag that enables user to undo his click (follow/unfollow). Default is false.
  • isReadonly - boolean flag that disables increasing counter value. Default is false.
  • isButtonLast - boolean flag that defines order of text and button. Default is false.
  • actionDoText - text shown on button initially.
  • actionUndoText - text shown on button if isUndoable === true and user already clicked the button.
  • actionDoneText - text shown on button if isUndoable === false and user already clicked the button.

Firebase security rules

Add following firebase security rules if you want to prevent users from arbitrary changing your counters. We allow incremental vote submissions:

{
    "rules": {
        ".read": true,
        "$counter": {
          ".write": "!root.child($counter).exists() || ((newData.val() - data.val()) === 1) || ((newData.val() - data.val()) === -1)",
          "presence": {
            ".write": true
          }
        }
    }
}

TODO

  • [x] implement undo
  • [x] online users counter
  • [x] create subcomponents
  • [ ] betters styles customization
  • [ ] auth support