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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@luxonauta/use-vibration

v1.0.8

Published

🪝 A React hook for controlling device vibration

Readme

useVibration

A React hook for controlling device vibration.

Why should we use more haptic feedback on the web? Please read about it here.

Installation

npm install @luxonauta/use-vibration

Basic Usage

import useVibration, { VibrationPatterns } from "@luxonauta/use-vibration";

export const Component = () => {
  const [{ isSupported, isVibrating }, { vibrate, stop }] = useVibration();

  if (!isSupported) {
    return <p>Vibration not supported on your device</p>;
  }

  return (
    <>
      <button
        type="button"
        onClick={() => vibrate(VibrationPatterns.tap)}
        disabled={isVibrating}
      >
        {isVibrating ? "Vibrating" : "Tap me for haptic feedback"}
      </button>
      {isVibrating && (
        <button type="button" onClick={stop}>
          Stop Vibration
        </button>
      )}
    </>
  );
};

API Reference

Hook Return Values

const [state, controls] = useVibration();

State Object

| Property | Type | Description | | ------------- | --------- | ----------------------------------------- | | isSupported | boolean | Whether the device supports vibration | | isVibrating | boolean | Whether the device is currently vibrating |

Controls Object

| Method | Type | Description | | --------- | -------------------------------------- | ------------------------------------------- | | vibrate | (pattern?: VibrationPattern) => void | Triggers vibration with an optional pattern | | stop | () => void | Stops any ongoing vibration |

Types

// Single duration or pattern array
type VibrationPattern = number | number[];

Predefined Patterns

The hook comes with common vibration patterns for different interactions:

| Pattern | Description | Value | | -------------- | -------------------- | --------------------------------------------------------------------------------------- | | tap | Subtle feedback | 100 | | standard | Standard vibration | 200 | | heavy | Emphasis | 500 | | double | Double-tap pattern | [100, 30, 100] | | triple | Triple-tap pattern | [100, 30, 100, 30, 100] | | success | Success feedback | [100, 50, 200] | | error | Error or warning | [300, 100, 500] | | notification | For notifications | [200, 100, 100] | | sos | SOS in morse code | [100, 100, 100, 100, 100, 100, 300, 100, 300, 100, 300, 100, 100, 100, 100, 100, 100] | | heartbeat | Heartbeat simulation | [100, 100, 100, 400] |

Advanced Usage

Custom Patterns

You can create custom vibration patterns using arrays where:

  • Even-indexed elements (0, 2, 4, ...) specify vibration durations;
  • Odd-indexed elements (1, 3, 5, ...) specify pause durations.
// Pattern: vibrate 200ms → pause 100ms → vibrate 400ms → pause 100ms → vibrate 200ms
const customPattern = [200, 100, 400, 100, 200];
vibrate(customPattern);

Creating UI Feedback

const FeedbackApp = () => {
  const [, { vibrate }] = useVibration();

  const handleSuccess = () => {
    // Haptic feedback
    vibrate(VibrationPatterns.success);
    // Visual feedback
    setStatus("Success!");
  };

  const handleError = () => {
    // Haptic feedback
    vibrate(VibrationPatterns.error);
    // Visual feedback
    setStatus("Error!");
  };

  // App
};

Game Example

const Game = () => {
  const [, { vibrate }] = useVibration();

  const handleCollision = (intensity) => {
    // Adjust the vibration based on collision intensity
    const duration = Math.min(Math.round(intensity * 300), 1000);
    vibrate(duration);
  };

  // Game
};

Browser Compatibility

The Vibration API is supported across most modern browsers:

Desktop Browsers

  • Chrome: 32+;
  • Edge: 79+;
  • Opera: 19+;
  • Firefox: Not supported;
  • Safari: Not supported.

Mobile Browsers

  • Chrome for Android: 32+;
  • Firefox for Android: 79+;
  • Opera for Android: 19+;
  • Samsung Internet: 2.0+;
  • "WebView Android": 4.4.3+;
  • Safari iOS: Not supported.

Important Notes

  • The Vibration API is primarily designed for mobile devices;
  • Desktop browsers may support the API, but won't produce actual vibration.

Recommendation: Always check isSupported before using vibration features in your app.

Best Practices

  1. Always check support first

    const [{ isSupported }] = useVibration();
    if (!isSupported) return <AlternativeFeedback />;
  2. Use sparingly

    • Excessive vibration can be annoying and drain battery. Use only for important feedback.
  3. Respect user preferences

    • Consider adding a setting to disable vibration.
  4. Provide alternatives

    • Always pair vibration with visual feedback for accessibility.
  5. Keep patterns simple

    • Complex patterns may not work consistently across devices.

Limitations

  • Some Android devices may ignore pattern details and use their default vibration;
  • Vibration might not work when browser is in background.

License

MIT