useLongPress
Detects long-press pointer gestures with movement threshold cancellation and click suppression.
The useLongPress hook returns pointer and click event handlers that invoke a callback when the user presses and holds an element for threshold milliseconds, cancelling automatically if the pointer moves beyond moveThreshold and suppressing the subsequent synthetic click event.
Installation
Usage
Examples
Long Press vs. Normal Click
Spread the returned handlers onto a button that also has a normal onClick—if a long press completes, the click event is suppressed automatically.
Lifecycle Callbacks (onStart, onFinish, onCancel)
Track press progress and distinguish completed long presses from cancelled ones using onStart, onFinish, and onCancel.
API Reference
UseLongPressOptions
Configuration options and lifecycle callbacks for the long-press gesture.
threshold?moveThreshold?preventClick?click event after a long press triggerscancelOnLeave?filterEvents?(eventReactPointerEvent<T>onStart?(eventReactPointerEvent<T>onFinish?(eventReactPointerEvent<T>onCancel?threshold elapses(eventReactPointerEvent<T>UseLongPressHandlers
DOM event handlers returned by the hook to spread onto the target element.
onPointerDownrequiredeventReactPointerEvent<T>onPointerMoverequiredmoveThresholdeventReactPointerEvent<T>onPointerUprequiredeventReactPointerEvent<T>onPointerLeaverequiredeventReactPointerEvent<T>onPointerCancelrequiredeventReactPointerEvent<T>onClickCapturerequiredeventReactMouseEvent<T>