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

@render-props/counter

v0.1.21

Published

A state container which provides an interface for bound-value counting.

Downloads

9

Readme

Counter

A state container which provides an interface for bound-value counting.

Installation

yarn add @render-props/counter or npm i @render-props/counter

Usage

import Counter from '@render-props/counter'

const LikesControl = ({value, step, incr, decr, setValue, setStep}) => (
  <div>
    <span>
      Number of likes: {value}
    </span>
    <a onClick={incr}>
      Like
    </a>
    <a onClick={decr}>
      Dislike
    </a>
    <button onClick={() => setValue(12)}>
      Set value to '12'
    </button>
    <button onClick={() => setStep(3)}>
      Set step to '3'
    </button>
  </div>
)

const Likes = props => (
  <div>
    <Counter
      onChange={console.log}
      initialValue={10}
      minValue={0}
      maxValue={24}
      onBoundMin={
        function ({setValue, maxValue}) {
          setValue(maxValue)
        }
      }
      onBoundMax={
        function ({setValue, minValue}) {
          setValue(minValue)
        }
      }
    >
      {LikesControl}
    </Counter>
  </div>
)

Props

  • initialValue {number} {default: 0}
    • the value the counter will start at
  • initialStep {number} {default: 1}
    • the default step amount of incr and decr
  • cast {function} {default: parseInt}
    • the typecast of the value, e.g. parseFloat
  • minValue {number}
    • the minimum value the counter is bound by
  • maxValue {number}
    • the maximum value the counter is bound by
  • onBoundMin {function}
    • called when the bound minimum has been reached. Callback should include one argument for object: {value, step, minValue, maxValue, setValue, incr, decr}.
  • onBoundMax {function}
    • called when the bound maximum has been reached. Callback should include one argument for object: {value, step, minValue, maxValue, setValue, incr, decr}.
  • onChange {function}
    • called each time the value changes. Callback accepts one argumet for value
  • onIncr {function}
    • called each time the value increments. Callback accepts one argumet for value
  • onDecr {function}
    • called each time the value decrements. Callback accepts one argumet for value

Render Props

Methods

  • incr ([by <number>])
    • increments the value by @by if defined, otherwise the prop step
  • decr ([by <number>])
    • decrements the value by @by if defined, otherwise the prop step
  • setValue (value <number>)
    • sets the value to @value
  • setStep (step <number>)
    • sets the default step to @step

State

  • value {number}
    • the current value of the counter
  • step {number}
    • the default step amount of the counter in incr() and decr()