react-swipe-hook
v0.1.2
Published
A hook for running callbacks on swipe
Downloads
2
Readme
react-swipe-hook
A hook for running callbacks on swipe
Api
Params
minimumDistance
onSwipeUp
onSwipeRight
onSwipeDown
onSwipeLeft
Returns
Array of onTouchStart
and onTouchEnd
event handlers.
Example usage
const ExampleComp = () => {
const [output, setOutput] = useState('no output')
const [onTouchStart, onTouchEnd] = useSwipeCallback(
40, //the minimum swipe distance
() => setOutput('The user swiped up!'),
() => setOutput('The user swiped right!'),
() => setOutput('The user swiped down!'),
() => setOutput('The user swiped left!')
)
return (
<>
<div
data-testid="swipe-area"
onTouchStart={onTouchStart}
onTouchEnd={onTouchEnd}
/>
<div data-testid="test-output">{output}</div>
</>
)
}