Docs
useSwipe

Detect swipe gestures on touch devices with useSwipe, providing options for direction and threshold.

Loading...

Installation

pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-swipe

Usage

"use client"
 
import { useSwipe } from "@/hooks/use-swipe"
 
export function Component() {
  const handlers = useSwipe({
    onSwipe: (direction) => {
      console.log("Swiped:", direction)
    },
  })
 
  return (
    <div
      {...handlers}
      style={{ width: "100%", height: "100vh", backgroundColor: "lightgray" }}
    >
      <h1>Swipe in any direction</h1>
    </div>
  )
}

API Reference

Parameters

NameTypeDescriptionDefault ValueOptional
onSwipe(direction: string) => voidCallback function triggered on swipe.-No
thresholdnumberMinimum distance to trigger a swipe.50Yes

Return Values

NameTypeDescription
onTouchStart() => voidTouch start event handler.
onTouchMove() => voidTouch move event handler.
onTouchEnd() => voidTouch end event handler.
onMouseDown() => voidMouse down event handler.