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-boop-simple

v0.1.0

Published

React hook for Josh W. Comeau's "Boop" effect.

Downloads

30

Readme

use-boop-simple

Minimal React hook for Josh W. Comeau's "Boop" effect.

Designed with bundle size in mind - less than 3KB gzipped!

use-boop-simple itself is less than 1.5KB gzipped.

Internally, use-boop-simple uses wobble for spring physics, which is 1.5-1.7KB gzipped.

Comparatively, animation libraries like React Spring and Framer Motion are far larger:

Install

npm install use-boop-simple
yarn add use-boop-simple
pnpm add use-boop-simple

Usage

import { useBoop } from "use-boop-simple";

function Boop({ children }) {
  const [style, trigger] = useBoop({ rotate: 15 });
  //     ^? { transform: "translate(Xpx, Ypx) rotate(Rdeg) scale(S)" }

  return (
    <span style={style} onMouseEnter={trigger}>
      {children}
    </span>
  );
}

API

useBoop(options): [style, trigger]

A hook that returns a tuple containing a CSS style object and a function to trigger the boop effect. The style object should be applied to the element you want to animate.

Respects the user's preference for reduced motion. If the user prefers reduced motion, the style object will be empty.

options

Type: object

x

Type: number
Default: 0

The target value to translate towards on the x-axis.

y

Type: number
Default: 0

The target value to translate towards on the y-axis.

rotate

Type: number
Default: 0

The target value to rotate towards.

scale

Type: number
Default: 1

The target value to scale towards.

tension

Type: number
Default: 300

Stiffness of the spring.

friction

Type: number
Default: 10

Damping of the spring's motion due to the forces of friction.

timing

Type: number
Default: 150

How long the boop effect should last, in milliseconds, before animating back to the original state.

usePrefersReducedMotion()

A hook that returns a boolean indicating whether the user prefers reduced motion.

Reflects the current state of the prefers-reduced-motion media query.

Limitations

  • Does not support all possible transform values (e.g. skew, 3D transforms, transformations on individual axes, etc.)

  • Does not support configuring the mass of the spring

  • Does not support advanced spring configuration (overdamping, rest velocity/displacement thresholds)

  • Currently uses useEffect instead of useLayoutEffect (see React Spring's useIsomorphicLayout for more information)

Development

Requires pnpm 9.

Related

  • use-boop - Extended react hook for Josh Comeau's boop effect. Uses React Spring.
  • react-spring - A spring physics based React animation library.
  • framer-motion - Open source, production-ready animation and gesture library for React.