You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Timer hooks look simple until real apps need pause/resume semantics, Strict Mode cleanup, async callbacks, polling that does not overlap, and lists with dozens of independent timers.
19
19
20
-
`@crup/react-timer-hook` keeps the API small and lets your app decide what time means:
20
+
`@crup/react-timer-hook` keeps the root import small and lets your app opt into heavier features only when needed:
21
21
22
-
- ⏱️ `useTimer()` for one lifecycle: stopwatch, countdown, clock, schedule, or custom flow.
23
-
- 🧭 `useTimerGroup()` for many keyed lifecycles with one shared scheduler.
24
-
- 🧩 `durationParts()` for display math without locale or timezone opinions.
22
+
- ⏱️ `useTimer()` from the root package for one lifecycle: stopwatch, countdown, clock, or custom flow.
23
+
- 🧭 `useTimerGroup()` from `/group` for many keyed lifecycles with one shared scheduler.
24
+
- 📡 `useScheduledTimer()` from `/schedules` for polling, overdue timing context, and opt-in diagnostics.
25
+
- 🧩 `durationParts()` from `/duration` for display math without locale or timezone opinions.
25
26
- 🧼 No formatting, timezone, audio, retry, cache, or data-fetching policy baked in.
26
27
- 🧪 Built for rerenders, Strict Mode, async callbacks, cleanup, and many timers.
27
28
- 🤖 Agent-friendly docs through hosted `llms.txt`, `llms-full.txt`, and an optional MCP docs helper.
`useScheduledTimer()` includes the lifecycle API from `useTimer()` plus schedule callbacks and opt-in debug events. It lives in a subpath so the root import stays small for clocks, stopwatches, and countdowns that do not need polling.
13
+
14
+
```ts
15
+
typeUseScheduledTimerOptions=UseTimerOptions& {
16
+
schedules?:TimerSchedule[];
17
+
debug?:TimerDebug;
18
+
};
19
+
```
20
+
21
+
Schedules run while active and default to `overlap: 'skip'`.
function useTimerGroup(options?:UseTimerGroupOptions):TimerGroupResult;
10
12
```
11
13
12
14
Use `useTimerGroup()` when every row needs independent pause, resume, cancel, restart, schedules, or `onEnd`.
13
15
14
-
Item schedules use the same `TimerSchedule` contract as `useTimer()`, including the third schedule context argument for intended fire time, actual fire time, next run time, and overdue interval count.
16
+
Item schedules use the same `TimerSchedule` contract as `useScheduledTimer()`, including the third schedule context argument for intended fire time, actual fire time, next run time, and overdue interval count.
`onEnd` fires once per generation. `restart()` creates a new generation.
30
28
31
-
Schedules run while active and default to `overlap: 'skip'`. The schedule callback receives a third `context` argument with `scheduledAt`, `firedAt`, `nextRunAt`, `overdueCount`, and `effectiveEveryMs`, so delayed browser timers can be measured without exposing timeout handles.
29
+
The root `useTimer()` export is lifecycle-only to keep the default bundle small. Use `@crup/react-timer-hook/schedules` when you need polling schedules and schedule timing context.
`@crup/react-timer-hook` gives React apps a small timer lifecycle primitive instead of a formatting-heavy timer component.
12
+
`@crup/react-timer-hook` gives React apps a small root timer primitive and optional subpath hooks for schedules, groups, diagnostics, and duration helpers.
13
13
14
14
It is built for Strict Mode, rerenders, async callbacks, cleanup, and pages with many independent timers.
0 commit comments