Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.72 KB

README.md

File metadata and controls

55 lines (42 loc) · 1.72 KB

React Long Press Hook

codecov npm type definitions NPM Downloads npm npm bundle size

React Long Press Hook

React hook for detecting click / tap / point and hold event

Main features

  • 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)

Installation

yarn add use-long-press

or

npm install --save use-long-press

Basic usage

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>;
};

Documentation

Full documentation can be found here.

Support

If you like my work, consider making a donation through Github Sponsors.

License

MIT © minwork