@awgv/use-timer-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.12 • Public • Published

@awgv/use-timer-hook

Latest NPM version Total amount of NPM downloads

The hook was created as an abstraction for notifications and is essentially a pausable setTimeout(). Neither setInterval() nor Date() objects are used, so if you need conventional clock functionality, you might want to check out packages that provide date/time information like amrlabib/react-timer-hook.

Usage

Package name:

@awgv/use-timer-hook

The hook is well-documented internally, so you can rely on your editor for intelligent code completion.

import { useTimer } from '@awgv/use-timer-hook'

export function YourComponent() {
  const {
    /**
     * ⏲ Returns true if the timer is running.
     */
    timerIsRunning,
    /**
     * ⏳ Stores the running timer’s remaining time and updates
     * when the timer is paused or restarted.
     */
    remainingTime,
    /**
     * 🔁 Starts or restarts the timer.
     */
    restartTimer,
    /**
     * ⏯ Resumes a paused timer.
     */
    resumeTimer,
    /**
     * ⏸ Pauses a running timer.
     */
    pauseTimer,
    /**
     * ⏹ Completely stops the timer.
     */
    stopTimer,
  } = useTimer({
    /**
     * The duration, in milliseconds, the timer should wait before
     * `callbackToExecuteOnExpiry()` is executed.
     */
    totalDurationInMilliseconds: 1000,
    /**
     * A function to be executed after the timer expires.
     */
    callbackToExecuteOnExpiry: () => {},
  })
}

Readme

Keywords

Package Sidebar

Install

npm i @awgv/use-timer-hook

Weekly Downloads

0

Version

1.0.12

License

MIT

Unpacked Size

8.37 kB

Total Files

9

Last publish

Collaborators

  • awgv