A modern, customizable countdown timer component for React with custom renderer, callbacks, and zero dependencies.
- ๐ฏ Modern React with hooks
- ๐จ Fully customizable (CSS classes + inline styles)
- ๐ญ Custom renderer with render props
- ๐ Lifecycle callbacks (onComplete, onTick, onStart, onPause, onStop, onMount)
- ๐ฎ Imperative API (start, pause, stop)
- ๐ถ Completion children
- ๐ฆ Zero dependencies
- โก Lightweight (~1.6KB gzipped)
- ๐ง TypeScript ready
npm install react-awesome-countdowntimer
# or
pnpm add react-awesome-countdowntimer
# or
yarn add react-awesome-countdowntimerimport CountdownTimer from 'react-awesome-countdowntimer';
import 'react-awesome-countdowntimer/dist/index.css';
function App() {
const endDate = new Date('2026-12-31T23:59:59');
return <CountdownTimer endDate={endDate} />;
}// With CSS classes
<CountdownTimer
endDate={endDate}
timerClassName="my-timer"
sectionClassName="my-section"
/>
// With inline styles
<CountdownTimer
endDate={endDate}
timerStyle={{ background: '#f0f4f8', padding: '30px' }}
sectionStyle={{ background: '#3b82f6', borderRadius: '12px' }}
/><CountdownTimer
endDate={endDate}
renderer={({ days, hours, minutes, seconds, completed }) => {
if (completed) return <div>๐ Time's up!</div>;
return <div>{days}d {hours}:{minutes}:{seconds}</div>;
}}
/><CountdownTimer
endDate={endDate}
onComplete={() => console.log('Done!')}
onTick={(delta) => console.log(delta.seconds)}
/><CountdownTimer endDate={endDate}>
<div>โจ Complete! โจ</div>
</CountdownTimer>const timerRef = useRef();
<CountdownTimer ref={timerRef} endDate={endDate} autoStart={false} />
<button onClick={() => timerRef.current.start()}>Start</button>
<button onClick={() => timerRef.current.pause()}>Pause</button>// Overtime mode (continue past zero)
<CountdownTimer endDate={endDate} overtime={true} />
// Days in hours (show 48h instead of 2d)
<CountdownTimer endDate={endDate} daysInHours={true} />
// Custom padding
<CountdownTimer endDate={endDate} zeroPadTime={3} /> // 001:002:003| Prop | Type | Default | Description |
|---|---|---|---|
endDate |
Date |
required | Target date/time |
renderer |
function |
- | Custom render function |
children |
ReactNode |
- | Content shown when complete |
onComplete |
function |
- | Callback when finished |
onTick |
function |
- | Callback every second |
onStart |
function |
- | Callback when started |
onPause |
function |
- | Callback when paused |
onStop |
function |
- | Callback when stopped |
onMount |
function |
- | Callback on mount |
autoStart |
boolean |
true |
Auto-start countdown |
zeroPadTime |
number |
2 |
Zero-padding digits (1-3) |
overtime |
boolean |
false |
Continue past zero |
daysInHours |
boolean |
false |
Show hours instead of days |
timerClassName |
string |
'' |
Timer container class |
sectionClassName |
string |
'' |
Section class |
timeClassName |
string |
'' |
Time number class |
labelClassName |
string |
'' |
Label class |
timerStyle |
object |
- | Timer container styles |
sectionStyle |
object |
- | Section styles |
timeStyle |
object |
- | Time number styles |
labelStyle |
object |
- | Label styles |
The renderer function receives:
{
total: number; // Milliseconds remaining
days: number; // Days remaining
hours: number; // Hours remaining
minutes: number; // Minutes remaining
seconds: number; // Seconds remaining
completed: boolean; // Is complete
formatted: { // Zero-padded strings
days: string;
hours: string;
minutes: string;
seconds: string;
}
}const ref = useRef();
ref.current.start(); // Start countdown
ref.current.pause(); // Pause countdown
ref.current.stop(); // Stop countdown
ref.current.isPaused(); // Returns boolean
ref.current.isStopped(); // Returns boolean
ref.current.isCompleted(); // Returns boolean.react-countdown-timer- Main container.react-countdown-section- Time unit box.react-countdown-time- Number display.react-countdown-label- Label text
MIT ยฉ Hassan Tauqeer
Give a โญ๏ธ if this project helped you!
