BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/Wednesday UI/use-countdown

Use Countdown

wednesday-ui/use-countdown
FreeHook

A hook for creating a countdown timer

Install it

npx shadcn@latest add https://ui.ednesdayw.com/r/use-countdown.json

Source

src/registry/hooks/use-countdown.tsui.ednesdayw.com/r/use-countdown.json
1import { useCallback, useEffect, useState } from "react";
2
3interface UseCountdownType {
4 initialSeconds: number;
5 autoStart?: boolean;
6 onComplete?: () => void;
7}
8
9type CountdownState = "idle" | "running" | "finished";
10
11export const useCountdown = ({
12 initialSeconds,
13 autoStart = false,
14 onComplete,
15}: UseCountdownType) => {
16 const [countdown, setCountdown] = useState(Math.max(initialSeconds, 0));
17 const [status, setStatus] = useState<CountdownState>(
18 autoStart ? "running" : "idle",
19 );
20
21 const start = useCallback(() => {
22 if (countdown <= 0) {
23 setCountdown(Math.max(initialSeconds, 0));
24 }
25
26 setStatus("running");
27 }, [initialSeconds, countdown]);
28
29 const reset = useCallback(() => {
30 setCountdown(Math.max(initialSeconds, 0));
31 setStatus("idle");
32 }, [initialSeconds]);
33
34 useEffect(() => {
35 if (status === "idle" || status === "finished") return;
36
37 const interval = setInterval(() => {
38 setCountdown((prev) => {
39 const next = prev - 1;
40 if (next <= 0) {
41 clearInterval(interval);
42 setStatus("finished");
43 onComplete?.();
44 return 0;
45 }
46 return next;
47 });
48 }, 1000);
49
50 return () => clearInterval(interval);
51 }, [status, countdown, onComplete]);
52
53 return {
54 countdown,
55 status,
56 start,
57 reset,
58 setCountdown,
59 };
60};
61
62export type UseCountdownReturn = ReturnType<typeof useCountdown>;

Files it writes

  • src/registry/hooks/use-countdown.ts

Facts

Registry
Wednesday UI
Type
registry:hook
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-04
Last confirmed
today

Go to the source

ui.ednesdayw.com xxxijustwei/ednesdayW on GitHub Raw registry item This item as JSON

More from Wednesday UI

All 99 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Use Disclosureuse-disclosureWednesday UIHooksFree1 dep
Use Media Queryuse-media-queryWednesday UIHooksFreeno deps
Use Rippleuse-rippleWednesday UIHooksFreeno deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex