1.0.12 • Published 5 years ago

timer-hook v1.0.12

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

timer-hook

Demo: https://codesandbox.io/s/timer-hook-example-ze88r

Usage

import React from 'react';
import { useTimer } from 'timer-hook';

const App = () => {
  const { time, start, pause, reset, isRunning } = useTimer();

  return (
    <>
      <div>Time: {time}</div>
      <div>
        <button onClick={start}>{isRunning ? 'Start' : 'Running'}</button>
        <button onClick={pause}>Pause</button>
        <button onClick={reset}>Reset</button>
      </div>
    </>
  );
};

Configuration

All configurations are optional

PropertyTypeDefault valueDescription
endTimenumbernullend time for the timer
initialTimenumber0starting value for the timer
intervalnumber1000the interval between each tick in milliseconds
onEndfunctioncallback function to run when timer is over
stepnumber1the value to change by each tick
typestring"INCREMENT""INCREMENT" or "DECREMENT"
1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago