UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

23 lines (22 loc) 1.01 kB
import { RefObject } from 'react'; type SwipeCallback = (event: TouchEvent) => void; interface UseSwipeOptions { threshold?: number; onSwipeLeft?: SwipeCallback; onSwipeRight?: SwipeCallback; onSwipeUp?: SwipeCallback; onSwipeDown?: SwipeCallback; } /** * Custom hook to detect swipe gestures (left, right, up, down) on a target element. * * @param ref - A React ref attached to the target element. * @param options - Configuration options including swipe callbacks and threshold. * @param options.threshold - Minimum distance (px) to be considered a swipe (default: 50). * @param options.onSwipeLeft - Callback for left swipe. * @param options.onSwipeRight - Callback for right swipe. * @param options.onSwipeUp - Callback for up swipe. * @param options.onSwipeDown - Callback for down swipe. */ export declare const useSwipe: <T extends HTMLElement>(ref: RefObject<T>, { threshold, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, }?: UseSwipeOptions) => void; export {};