From 24ae8f392cc07024d93ba8508ea8bcdfd7f146eb Mon Sep 17 00:00:00 2001 From: Ward Oosterlijnck Date: Sun, 13 Oct 2019 22:28:58 +1100 Subject: [PATCH] useVibrate docs --- README.md | 1 + docs/useVibrate.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/README.md b/README.md index ebe6c734..15a1823a 100644 --- a/README.md +++ b/README.md @@ -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.
diff --git a/docs/useVibrate.md b/docs/useVibrate.md index e69de29b..957d0114 100644 --- a/docs/useVibrate.md +++ b/docs/useVibrate.md @@ -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 ( +
+ +
+ ); +}; +``` + +## Reference + +```ts +useVibrate( + enabled: boolean = true, + pattern: number | number[] = [1000, 1000], + loop: boolean = true +): void; +```