fn

useVibrate

v0.0.14testeddemo

Reactive 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

ParameterTypeDescription
options?UseVibrateOptionsConfiguration options

Returns

UseVibrateReturnSupport flag, reactive pattern, vibrate/stop actions, and optional interval controls
PropertyTypeDescription
isSupportedComputedRef<boolean>Whether the Vibration API is supported in the current environment.
patternRef<Arrayable<number>>The reactive vibration pattern. Mutating it changes what vibrate() plays by default.
intervalControls?UseIntervalFnReturnPause/resume controls for the interval loop. Only present when interval > 0.
vibrate(pattern?: Arrayable<number>) => voidTrigger a vibration. Falls back to the configured pattern when called without arguments.
stop() => voidStop any ongoing vibration and pause the interval loop (if any).