@barelyreaper/background-timer
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

background-timer

Simple react hook to run a timer in the background

Motivation

Nothing really, pulled it off a project I wrote it for and now it's a package.

Install

npm i @barelyreaper/background-timer

Usage

import { useBackgroundTimer, msTimestamp } from 'background-timer';

export default function App() {
  /**
   * @param milliseconds
   * @returns {timer: milliseconds, reset: function} resets the timer
   */

  const { timer, reset } = useBackgroundTimer(2 * 1000 * 60,{
    onTimerEnd:()=>{
      alert("Timer Ended");
    }
  });
  

  return <>
    <p>{msTimestamp(timer)}</p>
    <button disabled={timer>0} onClick={()=>reset()}>Reset Timer</button>
  </>;
}

Package Sidebar

Install

npm i @barelyreaper/background-timer

Weekly Downloads

17

Version

0.0.13

License

MIT

Unpacked Size

5.75 kB

Total Files

9

Last publish

Collaborators

  • barelyreaper