UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

22 lines (21 loc) 1.09 kB
import { RefObject } from 'react'; type LongPressCallback = (event: MouseEvent | TouchEvent) => void; interface UseLongPressOptions { threshold?: number; onStart?: (event: MouseEvent | TouchEvent) => void; onEnd?: (event: MouseEvent | TouchEvent) => void; onCancel?: (event: MouseEvent | TouchEvent) => void; } /** * Custom hook to detect long press events on an element. * * @param ref - A React ref attached to the target element. * @param callback - Function to call when a long press is detected. * @param options - Optional configuration for the long press behavior. * @param options.threshold - Duration in ms until the press is considered long (default: 400). * @param options.onStart - Callback fired when the press starts. * @param options.onEnd - Callback fired when the press ends. * @param options.onCancel - Callback fired if the press is cancelled before duration. */ export declare const useLongPress: (ref: RefObject<HTMLElement | null>, callback: LongPressCallback, { threshold, onStart, onEnd, onCancel, }?: UseLongPressOptions) => void; export {};