ImportantVibrations can only be triggered after a user interaction (like a click) on the page. Programmatic vibrations without a prior gesture will be blocked by the browser.
TipYou can create haptic feedback patterns by passing an array, such as [200, 100, 200], where values represent [vibrate, pause, vibrate].
The useVibration hook abstracts the navigator.vibrate API, allowing you to trigger haptic feedback through a single pulse or complex patterns (vibrate-pause sequences). It is designed to be unopinionated and safely handles environments where the API is unavailable, such as desktop browsers or Server-Side Rendering (SSR) contexts.
| Name | Type | Description |
|---|---|---|
| cancel | () => void | Immediately stops any ongoing vibration by calling the API with a 0 duration. |
| isSupported | boolean | Indicates if the browser and device hardware support the Vibration API. |
| vibrate | (pattern: VibrationPattern) => boolean | Triggers vibration based on a number (ms) or an array (vibrate/pause ms). Returns true if successful. |