UNPKG

reactuals

Version:

A useful package providing a collection of 50+ React hooks and utilities to simplify React development.

23 lines (22 loc) 767 B
import { useCallback, useState } from "react"; export function useWebVibration() { const [error, setError] = useState(null); const isSupported = typeof navigator !== "undefined" && "vibrate" in navigator; const vibrate = useCallback((pattern) => { if (!isSupported) { setError(new Error("Vibration API not supported")); return false; } try { const success = navigator.vibrate(pattern); setError(null); return success; } catch (err) { const error = err instanceof Error ? err : new Error("Failed to vibrate"); setError(error); return false; } }, [isSupported]); return { vibrate, isSupported, error }; }