useVibrate docs

This commit is contained in:
Ward Oosterlijnck 2019-10-13 22:28:58 +11:00
parent 9df69c6e00
commit 24ae8f392c
2 changed files with 32 additions and 0 deletions

View File

@ -75,6 +75,7 @@
- [`useDrop` and `useDropArea`](./docs/useDrop.md) — tracks file, link and copy-paste drops.
- [`useFullscreen`](./docs/useFullscreen.md) — display an element or video full-screen. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/ui-usefullscreen--demo)
- [`useSpeech`](./docs/useSpeech.md) — synthesizes speech from a text string. [![][img-demo]](https://codesandbox.io/s/n090mqz69m)
- [`useVibrate`](./docs/useVibrate.md) — provide physical feedback using the [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API). [![][img-demo]](https://streamich.github.io/react-use/?path=/story/ui-usevibrate--demo)
- [`useVideo`](./docs/useVideo.md) — plays video, tracks its state, and exposes playback controls. [![][img-demo]](https://streamich.github.io/react-use/?path=/story/ui-usevideo--demo)
- [`useWait`](./docs/useWait.md) — complex waiting management for UIs.
<br/>

View File

@ -0,0 +1,31 @@
# `useVibrate`
React UI hook to provide physical feedback with device vibration hardware using the [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API).
## Usage
```jsx
import {useVibrate} from 'react-use';
const Demo = () => {
const [vibrating, toggleVibrating] = useToggle(false);
useVibrate(vibrating, [300, 100, 200, 100, 1000, 300], false);
return (
<div>
<button onClick={toggleVibrating}>{vibrating ? 'Stop' : 'Vibrate'}</button>
</div>
);
};
```
## Reference
```ts
useVibrate(
enabled: boolean = true,
pattern: number | number[] = [1000, 1000],
loop: boolean = true
): void;
```