react-use-stopwatch
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

react-use-stopwatch

A React Stopwatch Hook

Installation

npm install react-hook-stopwatch
yarn add react-hook-stopwatch

Usage

import { useStopwatch } from "react-hook-stopwatch";
 
export const Stopwatch = () => {
  const [{ time, format }, start, stop, reset] = useStopwatch();
 
  return (
    <div>
      // Stopwatch Outputs
      <strong>{time}</strong>
      <strong>{format}</strong>
      // Stopwatch Inputs
      <button onClick={() => start()}>Start</button>
      <button onClick={() => stop()}>Stop</button>
      <button onClick={() => reset()}>Reset</button>
    </div>
  );
};
Output: 87660 // Milliseconds
Output: 00:01:27.66 // HH:mm:ss:ms

Readme

Keywords

Package Sidebar

Install

npm i react-use-stopwatch

Weekly Downloads

10

Version

2.1.2

License

MIT

Unpacked Size

10.8 kB

Total Files

6

Last publish

Collaborators

  • troykessler