useSwipe
Detects pointer swipe gestures and directions on a target element.
Loading preview...
The useSwipe hook detects directional swipe gestures ('left', 'right', 'up', 'down') on a target element using Pointer Events, enforcing both a minimum distance (threshold) and a maximum gesture duration (timeout).
Installation
Usage
Examples
Swipeable Carousel Container
Use onSwipeLeft and onSwipeRight to advance or rewind slides on touch and pointer devices.
Vertical Swipe to Dismiss
Listen to onSwipeDown to dismiss a bottom sheet or notification card when the user swipes downward.
API Reference
UseSwipeOptions
Configuration options and directional callbacks for swipe detection.
Property
Specification
threshold?numberdefault:50
Minimum distance in pixels required to recognize a swipe direction
Full Signature
enabled?uniondefault:true
Whether swipe detection is active
Full Signature
preventDefault?uniondefault:false
Call
event.preventDefault() during pointer movementFull Signature
onSwipeStart?function
Callback fired when a pointer down initiates a swipe.
Full Signature
Parameters
(eventPointerEventonSwipe?function
Callback fired during pointer movement once
threshold is exceeded.Full Signature
Parameters
(stateSwipeState, event: PointerEventonSwipeEnd?function
Callback fired when the pointer is released or cancelled.
Full Signature
Parameters
(stateSwipeState, event: PointerEventonSwipeLeft?function
Callback fired when a swipe finishes in the
'left' direction.Full Signature
Parameters
(eventPointerEventonSwipeRight?function
Callback fired when a swipe finishes in the
'right' direction.Full Signature
Parameters
(eventPointerEventonSwipeUp?function
Callback fired when a swipe finishes in the
'up' direction.Full Signature
Parameters
(eventPointerEventonSwipeDown?function
Callback fired when a swipe finishes in the
'down' direction.Full Signature
Parameters
(eventPointerEventSwipeState
Live swipe status, direction, and movement deltas returned by the hook.
Property
Specification
isSwipingunion
Whether a pointer swipe gesture is currently in progress.
Full Signature
directionSwipeDirection
Detected swipe direction once
threshold is exceeded.lengthXnumber
Horizontal distance swiped (
startX - currentX).lengthYnumber
Vertical distance swiped (
startY - currentY).