Skip to content

useLongPress ​

Category
Sensors

Hook that defines the logic when long pressing an element

typescript
import { useLongPress } from '@siberiacancode/reactuse';

Usage ​

typescript
const longPressing = useLongPress(ref, () => console.log('callback'));

Demo ​

Api ​

Parameters

NameTypeDefaultNote
targetTarget-The target element to be long pressed
callback(event: Event) => void-The callback function to be invoked on long press
options.threshold?number400The threshold time in milliseconds
options.onStart?(event: Event) => void-The callback function to be invoked on long press start
options.onFinish?(event: Event) => void-The callback function to be invoked on long press finish
options.onCancel?(event: Event) => void-The callback function to be invoked on long press cancel

Returns

void

Parameters

NameTypeDefaultNote
targetTarget-The target element to be long pressed
callback(event: Event) => void-The callback function to be invoked on long press
options.threshold?number400The threshold time in milliseconds
options.onStart?(event: Event) => void-The callback function to be invoked on long press start
options.onFinish?(event: Event) => void-The callback function to be invoked on long press finish
options.onCancel?(event: Event) => void-The callback function to be invoked on long press cancel

Contributors ​

Source • Demo