#100UIEasy

useVibrate

useVibrate

React UI hook to provide physical feedback with device vibration hardware using the Vibration API.

Usage

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

useVibrate(
  enabled: boolean = true,
  pattern: number | number[] = [1000, 1000],
  loop: boolean = true
): void;
// TODO: implement useVibrate
function notImplemented(..._args: any[]): any {
  throw new Error('Not implemented');
}
export default notImplemented;
export const useVibrate = notImplemented;

Open browser consoleTests