@21kb/react-vibration-hook 中文文档教程
@21kb/react-vibration-hook
振动 API 的 React 钩子
Install
npm
npm install --save @21kb/react-vibration-hook
Yarn
yarn add @21kb/react-vibration-hook
Usage
import useVibration from '@21kb/react-vibration-hook';
function Component() {
const [vibrate, vibration] = useVibration();
return (
<div>
<button onClick={() => vibrate()}>Vibrate for 200ms (the default)</button>
<button onClick={() => vibrate(350)}>Vibrate for 350ms</button>
<button onClick={() => vibrate([350, 200, 400, 200, 450, 200, 500])}>Vibrate for 350ms, then pause 200ms, and so on...</button>
</div>
)
}
License
使用MIT
@21kb/react-vibration-hook
React hook to use the Vibration API
Install
npm
npm install --save @21kb/react-vibration-hook
Yarn
yarn add @21kb/react-vibration-hook
Usage
import useVibration from '@21kb/react-vibration-hook';
function Component() {
const [vibrate, vibration] = useVibration();
return (
<div>
<button onClick={() => vibrate()}>Vibrate for 200ms (the default)</button>
<button onClick={() => vibrate(350)}>Vibrate for 350ms</button>
<button onClick={() => vibrate([350, 200, 400, 200, 450, 200, 500])}>Vibrate for 350ms, then pause 200ms, and so on...</button>
</div>
)
}
License
MIT