Skip to content

dshimkoski/use-countdown-seconds

Repository files navigation

Build Status

@rehooks/use-countdown-seconds

React hook for use-countdown-seconds.

Note: This is using the new React Hooks API Proposal which is subject to change until React 16.7 final.

You'll need to install react, react-dom, etc at ^16.7.0-alpha.0

Install

yarn add @rehooks/use-countdown-seconds

Usage

import useCountdownSeconds from '@rehooks/use-countdown-seconds'

function Component() {
  const {
    start,
    startTime,
    timeLeft,
    isWarning
  } = useCountdownSeconds(3, 2)

  if (!startTime) {
    return (
      <div>
        not started
        <button onClick={() => start(new Date())}>Start</button>
      ])
    )
  }

  return (
    <div>
      started ({timeLeft})
      {isWarning && (
        <div>
          <em>expiring soon</em>
          <button onClick={() => start(new Date())}>Restart</button>
        </div>
      )}
    </div>
  )
}

About

hook for countdown timer w/ warning

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published