useCountdown

Create countdown timers using useCountdown.

Install:

Note: This hook depends on React’s experimental useEffectEvent.

npm i @uidotdev/usehooks@experimental react@experimental react-dom@experimental

Description:

The useCountdown hook is useful for creating a countdown timer. By specifying an endTime and various options such as the interval between ticks and callback functions for each tick and completion, the hook sets up an interval that updates the count and triggers the appropriate callbacks until the countdown reaches zero. The countdown value is returned, allowing you to easily incorporate and display the countdown in your components.

Parameters

NameTypeDescription
endTimenumberThe end time of the countdown in milliseconds since the Unix epoch.
optionsobjectAn object containing the following options:
  • interval: The interval in milliseconds at which the countdown should tick.
  • onComplete: A callback function to be called when the countdown reaches zero.
  • onTick: A callback function to be called on each tick of the countdown.

Return Value

NameTypeDescription
countnumberThe current count of the countdown.

Demo:

Example:

More Hooks:

Sort: