use-countdown-hook
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

React Countdown hook

Dead simple React countdown hook which will return the remain time in the dd:hh:mm:ss format implemented by requestAnimationFrame

npm downloads

简体中文 | English

Install

yarn add use-countdown-hook

or

npm install use-countdown-hook

Usage

import { useCountDown } from 'use-countdown-hook'

const onTimeOver = useCallback(
  () => {
    console.log('time over...')
  },
[])

const [{ dd, hh, mm, ss }, { start, pause }] = useCountDown(60 * 1000, {
  startImmediately: false,
  onTimeOver
})

return (
  <>
    <p>
      <span>{ dd }Days</span>
      <span>{ hh }Hours</span>
      <span>{ mm }Minutes</span>
      <span>{ ss }Seconds</span>
    </p>
    <button onClick={ start }>Start</button>
    <button onClick={ pause }>Pause</button>
  </>
)

Readme

Keywords

none

Package Sidebar

Install

npm i use-countdown-hook

Weekly Downloads

2

Version

2.1.0

License

MIT

Unpacked Size

10 kB

Total Files

9

Last publish

Collaborators

  • liyiming22