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

v0.0.10

Published

Use easing functions with a pure React Hook

Downloads

725

Readme

use-easing

npm

Single dependency on React

use-easing helps you ease a value using a React Hook.

This package also provides a few easings, you can specify any easing you want.

The package is written using TypeScript.

Inspired by React CountUp

Package size: :package: 2.75kb!

Install

Available in NPM, as use-easing!

npm install use-easing

or

yarn install use-easing

Demo

  1. Clone repo git clone [email protected]:icyJoseph/use-easing.git
  2. Install dependencies yarn or npm i
  3. Run yarn start:demo or npm run start:demo
  4. Go to localhost:3001

Structure

The hook encapsulates a single effect, which kicks off a process that invokes requestAnimationFrame, until the easing value has arrived at its goal.

The effect depends on the end goal, the duration and the state of an internal trigger.

The hook returns, the value and a callback to alter the trigger.

Basic Props

end

The value will move toward this end goal, following a given easing curve and over a given period of time.

duration

Measured in seconds.

function App() {
  const { value } = useEasing({ end: 10, duration: 1 });
  return value;
}

What does it do?

If you provide only the basic props, the component starts on mount and goes up to 10, over 1 second. By default it uses, the easeInQuad.

function App() {
  const { value } = useEasing<number>({ end: 10, duration: 1 });
  return value;
}

If you are using TypeScript, bare in mind that easings are typed as shown.

export const easeInQuad: easing = (
  t: number,
  b: number,
  c: number,
  d: number
) => c * (t /= d) * t + b;

You can also specify the type of value by passing a type parameter to useEasing. Or better yet, provide your own custom easing!

t: current time, b: start, c: end - start, d: duration

Optional Props

start

By default the value starts at 0, but this can be specified with the start prop.

autoStart

The effect will kick off the process as soon as possible, to prevent this, declare autoStart false.

easingFn

The easing function. This function is invoked on every requestAnimationFrame, and it calculates the current value value.

More on easing functions here.

formatFn

Applied to the outcome of the easing function. For example:

const floor = x => Math.floor(x);
const fixed = x => x.toFixed(2);

You could even create a map where each number translates to some other symbol!

onCleanUp

Called when the effect is cleaned up.

onPauseResume

Called when the process is paused.

onStart

Called when the process starts.

onEnd

Called when the process ends.