New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-haptic

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-haptic

React hooks for haptic feedback

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

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

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

  • 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)

NameTypeDefaultDescription
optionsUseHapticOptions-Optional configuration object.
options.hapticDurationnumber100The duration (in milliseconds) for the vibration, if the Vibrate API is supported.

Return Value

NameTypeDescription
vibrate() => voidA function that triggers haptic feedback (vibration or Taptic-like feedback).

License

MIT

Keywords

iOS

FAQs

Package last updated on 20 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts