Docs
useVibration
Use the useVibration hook to control the vibration of a device, with options for duration and pattern.
Loading...
Installation
pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-vibration
Usage
"use client"
import { useVibration } from "@/hooks/use-vibration"
export function Component() {
const { vibrate } = useVibration()
return (
<Button
onClick={() => {
vibrate(200)
}}
>
Vibration
</Button>
)
}
API Reference
Parameters
Name | Type | Description | Default Value | Optional |
---|---|---|---|---|
defaultPattern | number[] | Default vibration pattern. | [100] | Yes |
options.loop | boolean | Whether to loop the vibration pattern. | false | Yes |
Return Values
Name | Type | Description |
---|---|---|
vibrate | (pattern: number | number[], options?: { loop?: boolean }) => void | Function to trigger vibration with a specified pattern and options. |
isVibrating | boolean | Indicates whether the device is currently vibrating. |
stop | () => void | Function to stop the current vibration. |
isSupported | boolean | Indicates whether the vibration feature is supported on the device. |