useCountdown

About

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

Examples

Basic example

const endTime = new Date(Date.now() + 10000);
import { useCountdown } from "rooks";
export default function App() {
  const count = useCountdown(endTime, {
    interval: 1000,
    onDown: time => console.log("onDown", time),
    onEnd: time => console.log("onEnd", time),
  });
  return count;
}

Arguments

ArgumentTypeDescriptionDefault value
endTimeDatethe time when the countdown should endundefined
options.intervalnumbermilliseconds that it takes count down once1000
options.onDownfunction(time) => , callback that would be called every intervalundefined
options.onEndfunction(time) => , callback that would be called when the countdown endsundefined

Return Value

TypeDescription
numberrest amount of intervals it takes to count down to the endTime

Join the community!

Join our discord server! You can click the floating discord icon at the bottom right of the screen and chat with us!

Powered by vercel