react-haptic
Version:
React hooks for haptic feedback
34 lines (32 loc) • 1.02 kB
TypeScript
/**
* Configuration options for the `useHaptic` hook.
*/
type UseHapticOptions = {
/**
* The duration of the vibration in milliseconds.
* @default 100
*/
hapticDuration?: number;
};
/**
* The return type for `useHaptic`, providing the `vibrate` method.
*/
type UseHaptic = {
/**
* Triggers the haptic feedback mechanism.
*/
vibrate: () => void;
};
/**
* A React hook that provides haptic feedback.
*
* On devices where `navigator.vibrate` is supported, it uses the Vibrate API.
* On iOS devices (where `vibrate` is typically not supported), it falls back
* to clicking a hidden switch element to trigger haptic feedback.
*
* @param {UseHapticOptions} [options] - Optional configuration for the hook.
* @param {number} [options.hapticDuration=100] - The duration of the vibration in milliseconds.
* @returns {UseHaptic} An object containing the `vibrate` function.
*/
declare const useHaptic: ({ hapticDuration, }?: UseHapticOptions) => UseHaptic;
export { useHaptic };