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

use-smooth-count

v1.0.1

Published

Easily interpolate to a provided value with a React hook.

Downloads

373

Readme

∿ use-smooth-count ∿

Easily interpolate to a provided value with a simple React hook.

Demo
Example (the banner)

Features

  • 📦 Tiny: use-smooth-count is <10kb unpacked, and even less when minified
  • 👨‍💻 Easy to use, guaranteeing seamless integration into your website
  • ⌨️ Strongly typed: use-smooth-count uses TypeScript to ensure good practices, and eliminate any sneaky bugs

Usage

useSmoothCount requires 3 parameters:

  • a ref (to the element that holds the number)
  • a target (the number to reach)
  • a duration (how long it takes to reach that number)

There are many other optional parameters, such as curve and startAt. Detailed explanations are provided via JSDoc in index.ts

Example:

import { useSmoothCount } from "use-smooth-count";

const Element = () => {
    const ref = useRef(null);
    const count = useSmoothCount({ ref: ref, target: 183, duration: 3, curve: [0, 0.99, 0.01, 1] });

    return <div ref={ref} />;
};

The counter starts automatically unless you set preventStart to true, in which case you can manually call count.start() whenever you'd like.

Other working examples can be found in the example folder.

Things to Note

Certain bezier curves will not work, because at the moment the x-values of the coordinates are not taken into account for the path. This is due to the setInterval time being linear, and me being too lazy to figure out the math involved. If you know how to solve this, feel free to pull request.

There will probably be bugs. If you encounter one, please create an issue that includes the following information:

  • The issue itself
  • The expected behavior
  • The resulted behavior
  • How to reproduce (along with a direct code snippet that's producing it)

Certain logic/syntax may be subject to change. In the rare case that I need to rework something and cannot use the current syntax, I will try to find a way to keep the old method(s) in while the new ones are also introduced, as to not break any code that uses this package. If not, I'll try to let people know before updating it :+1:

Other

As always, feel free to star :star: this repo if you find it useful, as that helps out a ton and means a lot. Happy developing :)