1.0.0 • Published 2 years ago

@qriousgabriel/react-countdown-hook v1.0.0

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

react-countdown-hook

A very simple count down hook for React.

NPM JavaScript Style Guide

Install

NPM

npm install --save @qriousgabriel/react-countdown-hook

Yarn

yarn add @qriousgabriel/react-countdown-hook

Usage

// Timer.tsx

import * as React from 'react'
import useCountDown from '@qriousgabriel/react-countdown-hook'

export const Timer = () => {
  const { counter, pause, resume, isPaused } = useCountDown(120, 1000)
  const toggleTimer = () => {
    isPaused ? resume() : pause()
  }
  return (
    <React.Fragment>
      <div>Counter: {counter}</div>
      <button onClick={toggleTimer}>{isPaused ? 'Resume' : 'Pause'}</button>
    </React.Fragment>
  )
}

License

MIT © qriousgabriel