New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

use-long-press

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-long-press

React hook for detecting click (or tap) and hold event. Easy to use, highly customizable options, thoroughly tested.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49K
increased by1.04%
Maintainers
1
Weekly downloads
 
Created
Source

React Long Press Hook :point_down:

React hook for detecting click (or tap) and hold event.

Travis (.org) Codecov npm type definitions npm bundle size npm GitHub

  • Easy to use
  • Highly customizable options
  • Thoroughly tested

Install

yarn add use-long-press

or

npm install --save use-long-press

Basic Usage

import React from 'react'
import { useLongPress } from 'use-long-press'

const Example = () => {
  const bind = useLongPress(() => {
      console.log('Long pressed!');
  });

  return (
    <button {...bind}>
      Press me
    </button>
  )
}

Example

Edit useLongPress

Advanced usage

Callback can be either function or null if you want to disable the hook.

Additionally hook accepts options object as a second argument.

useLongPress(callback: (event?: MouseEvent | TouchEvent) => void | null, options?: LongPressOptions);

Options

Long press hook can be adjusted using options object, which allow you to fit it to your needs.

NameTypeDefaultDescription
thresholdnumber400Time user need to hold click or tap before long press callback is triggered
captureEventbooleanfalseIf React MouseEvent (or TouchEvent) should be supplied as first argument to callbacks
detectEnum('mouse' | 'touch' | 'both')'both'Which event handlers should be returned in bind object. In TS this enum is accessible through LongPressDetectEvents
onStartFunction() => {}Called when element is initially pressed (before starting timer which detects long press).

Can accept mouse or touch event if captureEvents option is set to true.
onFinishFunction() => {}Called when press is released (after triggering callback).

Can accept mouse or touch event if captureEvents option is set to true.
onCancelFunction() => {}Called when press is released before threshold time elapses, therefore before long press occurs.

Can accept mouse or touch event if captureEvents option is set to true.

License

MIT © minwork

Keywords

FAQs

Package last updated on 23 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc