1.0.0 • Published 4 years ago

@app-elements/use-successive-taps v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

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

PropTypeDefaultDescription
numTapsNumberNoneNumber of successive taps
delayNumberNonems pause allowed between taps
callbackFunctionNonefunction to invoke after successive taps