Rehooks
Hooks

useCountDown

A hook that offers countdown functionality with adjustable start, stop, and interval parameters.

useCountDown

A handy hook that gives you countdown capabilities, letting you start, stop, and reset the countdown with customizable options.

Usage

import { useCountDown } from "rehooks-ts";
 
const [counter, { startCountdown, stopCountdown, resetCountdown }] =
  useCountDown({
    countStart: 10,
    intervalMs: 1000,
    countStop: 0,
  });

API

useCountDown

function useCountDown({
  countStart,
  countStop = 0,
  intervalMs = 1000,
}: {
  countStart: number;
  countStop?: number;
  intervalMs?: number;
}): [
  number,
  {
    startCountdown: () => void;
    stopCountdown: () => void;
    resetCountdown: () => void;
  },
];

Parameters

NameTypeDescription
countStartnumberThe countdown's initial value.
countStopnumberThe value at which the countdown ends (default is 0).
intervalMsnumberThe time in milliseconds between countdown updates (default is 1000).

Returns

NameTypeDescription
countnumberThe current countdown value.
startCountdown() => voidA function to begin the countdown.
stopCountdown() => voidA function to pause the countdown.
resetCountdown() => voidA function to reset the countdown to the initial starting value.

On this page