Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-double-tap

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-double-tap

React hook for handling double tap on mobile devices

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

:point_up_2: React Double Tap Hook :point_up_2:

React hook for handling double tap on mobile devices

NPM NPM

Install

npm install --save use-double-tap

or

yarn add use-double-tap

Basic Usage

import React from 'react';

import { useDoubleTap } from 'use-double-tap';

const Example = () => {
    const bind = useDoubleTap(() => {
      // Your action here
      console.log('Double tapped');
    });
    
    return <button {...bind}>Tap me</button>;
}

Live demo

Advanced usage

Custom capture threshold

You can also manually specify time threshold for capturing double tap event (default: 300ms).

useDoubleTap(() => {
  // Your action here
}, 500);

In the example above, second tap must occur within 500ms period to register double tap.

Disable event binding

If you pass falsy value as callback (like null) double tap will not bind to the component.

useDoubleTap(null);

This allows you to dynamically control if event should be bound. For example:

const bind = useDoubleTap(isMobile ? () => {
  console.log('Double tapped');
} : null);

:warning: Warning

This hook internally use onClick event to detect double tap, so be careful not to override your existing event listener.

This is where disabling listener binding may come handy - you can use double tap detection only when necessary.

Why onClick?

Because it leverages built in event listener which can also detect mobile tap event.

This way we can get rid of complicated edge cases when combining onTouchStart onTouchEnd onTouchCancel onTouchMove events.

Also this approach greatly reduce package size as well as increase speed and flexibility.

License

MIT © minwork

Keywords

FAQs

Package last updated on 10 Sep 2019

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