fn
useVibrate
v0.0.14testeddemoReactive wrapper around the navigator.vibrate Vibration API.
Examples
ts
const { vibrate, stop, isSupported } = useVibrate({ pattern: [200, 100, 200] });
vibrate();ts
// Loop a pattern on an interval
const { vibrate, stop, intervalControls } = useVibrate({ pattern: [300, 100], interval: 2000 });
intervalControls?.resume();Demo
Loading demo…
Signature
ts
export function useVibrate(options: UseVibrateOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
options? | UseVibrateOptions | Configuration options |
Returns
UseVibrateReturnSupport flag, reactive pattern, vibrate/stop actions, and optional interval controls| Property | Type | Description |
|---|---|---|
isSupported | ComputedRef<boolean> | Whether the Vibration API is supported in the current environment. |
pattern | Ref<Arrayable<number>> | The reactive vibration pattern. Mutating it changes what vibrate() plays by default. |
intervalControls? | UseIntervalFnReturn | Pause/resume controls for the interval loop. Only present when interval > 0. |
vibrate | (pattern?: Arrayable<number>) => void | Trigger a vibration. Falls back to the configured pattern when called without arguments. |
stop | () => void | Stop any ongoing vibration and pause the interval loop (if any). |