Skip to content

useVibrate

Hook that provides vibrate api

browser
low
test coverage
Last changed: 7 months ago

TIP

This hook uses navigator.vibrate browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api

Installation

Library
CLI
Manual
typescript
import { useVibrate } from '@siberiacancode/reactuse';

Usage

typescript
const { supported, active, vibrate, stop, pause, resume } = useVibrate(1000);

Demo

Api

Parameters

NameTypeDefaultNote
options.patternUseVibratePattern-The pattern for vibration
options.interval?number0Time in milliseconds between vibrations

Returns

UseVibrateReturn

Type declaration

typescript
export type UseVibratePattern = number | number[];

export interface UseVibrateReturn {
  /** The support indicator */
  supported: boolean;
  /** The vibrating indicator */
  vibrating: boolean;
  /** The pause function */
  pause: () => void;
  /** The resume function */
  resume: () => void;
  /** The start function */
  start: (interval: number) => void;
  /** The vibrate function */
  trigger: (pattern?: UseVibratePattern) => void;
}

Source

SourceDemo

Contributors

D
debabin
debabin
N
Nurvive
Nurvive

Released under the MIT License.