Skip to content

layerhub-io/use-timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>
  );
};

About

Global timer for react applications. Hook.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published