0.1.1 • Published 3 years ago

@layerhub-io/use-timer v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

use-timer

Simple timer using React Context API. Can be accesible from any component.

Installation

npm i @layerhub-io/use-timer

Using pnpm:

pnpm i @layerhub-io/use-timer

Usage

Wrap you application with TimerProvider, then use it from anywhere your application.

import { TimerProvider, useTimer } from '@layerhub-io/use-timer';

const ParentApp = () => {
  return (
    <TimerProvider>
      <App />
    </TimerProvider>
  );
};

const App = () => {
  const { start, time, pause, reset, setTime } = useTimer();
  return (
    <div>
      <div onClick={start}>start</div>
      <div onClick={pause}>pause</div>
      <div onClick={reset}>reset</div>
      <div onClick={() => setTime(1000)}>set time 10</div>
      <div>{time}</div>
    </div>
  );
};
0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago