@app-elements/use-successive-taps

1.0.0 • Public • Published

useSuccessiveTaps

useSuccessiveTaps takes a number of taps, a delay, and a callback, then returns a function that will only invoke the callback when it itself is invoked the specified number of times (with a pause no greater than the specified delay).

Installation

npm install --save @app-elements/use-successive-taps

Usage

import { useSuccessiveTaps } from '@app-elements/use-successive-taps'

const Stateful = (props) => {
  // Create a handler to invoke "Test" mode only after our logo is tapped 10
  times.
  const handler = useSuccessiveTaps(10, 750, () => {
    dispatch(toggleTestMode())
  })
  
  return (
    <h1 onClick={handler}>Logo</h1>
  )
}

Props

Prop Type Default Description
numTaps Number None Number of successive taps
delay Number None ms pause allowed between taps
callback Function None function to invoke after successive taps

Package Sidebar

Install

npm i @app-elements/use-successive-taps

Weekly Downloads

3

Version

1.0.0

License

ISC

Unpacked Size

13.1 kB

Total Files

11

Last publish

Collaborators

  • adriaanwm
  • coryschadt
  • staydecent
  • trustfall