Hooks

useLongPress

Publisher

cermuel

50 hooks published

More from this publisher

useLongPress

Detect touch or pointer hold gestures.

useLongPress.tsx
import { useState } from "react";import { useLongPress } from "@cermuel/hooks/react";export function useLongPressExample() {  const [pressed, setPressed] = useState(false);  const press = useLongPress(() => setPressed(true));  return <button type="button" {...press.bind}>{pressed ? "Pressed" : "Hold"}</button>;}

Props

Param
Type
Default Value
handler
() => void
options?
LongPressOptions
{}

Returns

{ bind: { onPointerDown: () => void; onPointerUp: () => void; onPointerLeave: () => void; onPointerCancel: () => void; }; start: () => void; cancel: () => void; }