Vize

use-vibrate

Drive the Vibration API with validated, optionally repeating patterns.

Package @vizejs/composable/use-vibrate
Own the source vize lib pull composable:use-vibrate
Runtime exports useVibrate
Gzip budget 2048 B

Usage

import { useVibrate } from "@vizejs/composable/use-vibrate";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
useVibrate system experimental deterministic-fallback caller-managed caller, reactive-scope web, desktop globalThis, window tryOnScopeDispose

API

useVibrate

Drive the Vibration API with validated, optionally repeating patterns. Patterns alternate vibration and pause durations. With interval > 0 the pattern repeats until stop is called or the owning reactive scope stops, which also cancels an ongoing vibration. Server rendering: nothing vibrates and no timer starts; supported is false.

function useVibrate(options: UseVibrateOptions = {}): VibrateControls
const { vibrate, stop } = useVibrate({ pattern: [200, 100, 200] });
vibrate();

Types

VibrationHost

Minimal Vibration API (navigator).

Member Type Description
vibrate (pattern: VibrationPattern) => boolean Start (or with 0/[], cancel) a vibration. Returns whether it was accepted.

UseVibrateOptions

Options for useVibrate.

Member Type Description
pattern? MaybeRefOrGetter<VibrationPattern> Default pattern used by vibrate().
interval? number Repeat the pattern every interval milliseconds until stop; 0 vibrates once.
host? MaybeRefOrGetter<VibrationHost | null | undefined> Vibration capability for alternate runtimes and tests.
scheduler? TimeoutScheduler Timer host used for repetition.

VibrateControls

Reactive state and actions returned by useVibrate.

Member Type Description
supported ComputedRef<boolean> Whether the Vibration API is available.
vibrating Readonly<Ref<boolean>> Whether a (possibly repeating) vibration started by this composable is active.
vibrate (pattern?: VibrationPattern) => boolean Vibrate with pattern or the default pattern.
stop () => void Cancel the vibration and any repetition.