All Projects → minwork → use-double-tap

minwork / use-double-tap

Licence: MIT license
React hook for handling double tap on mobile devices

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to use-double-tap

Ysf
YSF Server Functions
Stars: ✭ 77 (+327.78%)
Mutual labels:  hooks, hook
React Universal Hooks
🎉 React Universal Hooks : just use****** everywhere (Functional or Class Component). Support React DevTools!
Stars: ✭ 148 (+722.22%)
Mutual labels:  hooks, hook
React Selector Hooks
Collection of hook-based memoized selector factories for declarations outside of render.
Stars: ✭ 84 (+366.67%)
Mutual labels:  hooks, hook
use-smooth-scroll
React hook which gives a smooth scrolling function.
Stars: ✭ 41 (+127.78%)
Mutual labels:  hooks, hook
React Nprogress
⌛️ A React primitive for building slim progress bars.
Stars: ✭ 173 (+861.11%)
Mutual labels:  hooks, hook
Fontmod
Simple hook tool to change Win32 program font.
Stars: ✭ 1,064 (+5811.11%)
Mutual labels:  hooks, hook
Hooks
Async middleware for JavaScript and TypeScript
Stars: ✭ 117 (+550%)
Mutual labels:  hooks, hook
Swr
React Hooks for data fetching
Stars: ✭ 20,348 (+112944.44%)
Mutual labels:  hooks, hook
React Use Wizard
🧙 A React wizard (stepper) builder without the hassle, powered by hooks.
Stars: ✭ 162 (+800%)
Mutual labels:  hooks, hook
Pinst
🍺 dev only postinstall hooks (package.json)
Stars: ✭ 162 (+800%)
Mutual labels:  hooks, hook
Webhook
webhook is a lightweight incoming webhook server to run shell commands
Stars: ✭ 7,201 (+39905.56%)
Mutual labels:  hooks, hook
Fre
👻 Tiny Footprint Concurrent UI library for Fiber.
Stars: ✭ 3,195 (+17650%)
Mutual labels:  hooks, hook
Use Onclickoutside
React hook for listening for clicks outside of an element.
Stars: ✭ 361 (+1905.56%)
Mutual labels:  hooks, hook
crypto-watchdog
Crypto Watchdog is an open-source developer friendly project, periodically queries crypto market and notifies potential pumps & recently added tokens/coins via web-hooks.
Stars: ✭ 22 (+22.22%)
Mutual labels:  hooks, hook
Radioactive State
☢ Make Your React App Truly Reactive!
Stars: ✭ 273 (+1416.67%)
Mutual labels:  hooks, hook
Swifthook
A library to hook methods in Swift and Objective-C.
Stars: ✭ 93 (+416.67%)
Mutual labels:  hooks, hook
hookr
PHP action and filter hook system
Stars: ✭ 39 (+116.67%)
Mutual labels:  hooks, hook
MouseInjectDetection
Simple method of checking whether or not mouse movement or buttons (<windows 10) are injected
Stars: ✭ 29 (+61.11%)
Mutual labels:  hooks, hook
React Intersection Observer
React implementation of the Intersection Observer API to tell you when an element enters or leaves the viewport.
Stars: ✭ 2,689 (+14838.89%)
Mutual labels:  hooks, hook
Useworker
⚛️ useWorker() - A React Hook for Blocking-Free Background Tasks
Stars: ✭ 2,233 (+12305.56%)
Mutual labels:  hooks, hook

👆 React Double Tap Hook 👆

React hook for handling double tap on mobile devices

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

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((event) => {
      // Your action here
      console.log('Double tapped');
    });

    return <button {...bind}>Tap me</button>;
}

export default Example;

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.

Additional options

Supplied as third argument.

useDoubleTap(() => {
  // Actions on double tap
}, 300, {
  // Options here
})

List of possible options:

Option Type Description
onSingleTap Function Callback for handling case when double tap is not triggered,
because of capture timeout.

For example if threshold parameter is 300ms and second tap occurs after 400ms
then onSingleTap is triggered after capture interval (300ms) expires.

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

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].