JSPM

  • Created
  • Published
  • Downloads 54
  • Score
    100M100P100Q74661F
  • License MIT

Count down to a target timestamp and call callbacks every second (or provided peried)

Package Exports

  • @rooks/use-countdown

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rooks/use-countdown) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@rooks/use-countdown

Count down to a target timestamp and call callbacks every second (or provided peried)

Build Status

Join the community on Spectrum

Installation

npm install --save @rooks/use-countdown

Importing the hook

import useCountdown from "@rooks/use-countdown"

Usage

const endTime = new Date(Date.now() + 10000);

function Demo() {
  const count = useCountdown(endTime, {
    interval: 1000,
    onDown: time => console.log('onDown', time),
    onEnd: time => console.log('onEnd', time),
  });
  return count;
}

render(<Demo/>)

Arguments

Argument Type Description Default value
endTime Date the time when the countdown should end undefined
options.interval number milliseconds that it takes count down once 1000
options.onDown function (time) => {}, callback that would be called every interval undefined
options.onEnd function (time) => {}, callback that would be called when the countdown ends undefined

Return Value

Type Description
number rest amount of intervals it takes to count down to the endTime