Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-haptic

ryotanakata18MIT1.0.1TypeScript support: included

React hooks for haptic feedback

iOS, Haptic, Haptics, Taptic, Haptic Feedback, iOS Haptic, Touch Feedback, React Hook, React Hooks, Vibrate API, Vibration, Cross-Platform, Mobile, iOS Safari, Taptic Engine, Touch Interaction, User Feedback, Browser Compatibility, Device Feedback, UI/UX

readme

react-haptic

haptic image

Lightweight | Cross-Platform | iOS-Like Haptics

A lightweight React Hook that mimics iOS-style haptic feedback. On devices supporting the Vibrate API, it directly triggers vibration. On iOS devices—where navigator.vibrate is generally unavailable—it leverages a hidden switch trick to produce Taptic-like feedback, similar to native iOS haptic interactions.

Install

Use your favorite package manager to install:

# npm
npm install react-haptic

# yarn
yarn add react-haptic

# pnpm
pnpm add react-haptic

Usage

import React from "react";
import { useHaptic } from "react-haptic";

const Component = () => {
  const { vibrate } = useHaptic();

  const handleClick = () => {
    vibrate(); // Trigger haptic feedback
  };

  return <button onClick={handleClick}>Click for Haptic</button>;
};

How It Works

  1. iOS devices Falls back to clicking a hidden switch element, which can trigger Taptic feedback in many iOS browsers.

  2. Non-iOS devices If navigator.vibrate is available, the device vibrates for the specified duration (default: 100ms).

Note iOS 16+ provides an experimental “Haptics API” behind a Safari flag. Until it's widely enabled, this library uses the hidden switch trick as a workaround.

API

useHaptic(options?: UseHapticOptions)

Name Type Default Description
options UseHapticOptions - Optional configuration object.
options.hapticDuration number 100 The duration (in milliseconds) for the vibration, if the Vibrate API is supported.

Return Value

Name Type Description
vibrate () => void A function that triggers haptic feedback (vibration or Taptic-like feedback).

License

MIT