useTimer

A hook for managing timers with start, stop, and restart functionality

Preview

Basic Timer

Timer with Controls

Completed count: 0

Installation

Usage

API Reference

Parameters

ParameterTypeDefaultDescription
delaynumber-The timer duration in milliseconds
onTimeout() => void-Callback function called when timer completes
enabledbooleantrueWhether the timer is enabled

Return Value

Returns an object with the following properties:

PropertyTypeDescription
isActivebooleanWhether the timer is currently running
remainingTimenumberRemaining time in milliseconds
start() => voidStarts the timer
stop() => voidStops the timer
restart(activate?: boolean) => voidRestarts the timer. If activate is true, starts even if not currently active

Examples

Auto-save Timer

Countdown Timer