Timer model to manage some countdown. Useful for classic pomodoro or any time-progress states, like notifications.
import { reatomTimer } from '@reatom/timer'
const pomodoroAtom = reatomTimer({
name: 'pomodoroAtom',
interval: 1000,
delayMultiplier: 1000,
progressPrecision: 2,
resetProgress: true,
})
The timer itself contains the ms remaining to the end of the timer (0
before start). Here is the list of available states and methods:
- progressAtom (
Atom<number>
) - from 0 to 1, (delay - remains) / delay
- intervalAtom (
AtomMut<number>
) - interval of ticks in ms - startTimer (
Action<[delay: number, passed?: number], Promise<void>>
) - start timer with the delay and optional start point - stopTimer (
Action<[], void>
) - stop timer manually - pauseAtom (
AtomMut<boolean>
) - allow to pause timer - pause (
Action<[], boolean>
) - switch pause state - endTimer (
Action<[], void>
) - track end of timer. Do not call manually!
Examples