React hook for detecting click / tap / point and hold event
- Mouse, Touch and Pointer events support
- Pass custom context and access it in callback
- Cancel long press if moved too far from the target
- Flexible callbacks:
onStart
,onMove
,onFinish
,onCancel
- Disable hook when necessary
- Filter undesired events (like mouse right clicks)
yarn add use-long-press
or
npm install --save use-long-press
Basic hook usage example to get started immediately
import React from 'react'; // No longer necessary in newer React versions
import { useLongPress } from 'use-long-press';
const Example = () => {
const handlers = useLongPress(() => {
// Your action here
console.log('Long pressed!');
});
return <button {...handlers()}>Press me</button>;
};
Full documentation can be found here.
If you like my work, consider making a donation through Github Sponsors.
MIT © minwork