React Countdown Component

2.3.6 · active · verified Sun Apr 19

react-countdown is a highly customizable React component designed to display countdowns. It is currently stable at version 2.3.6 and has seen active maintenance, with multiple bugfix and minor feature releases within the 2.x series. The library allows developers to define a target date and provides flexible rendering options, including a custom `renderer` function or rendering a child component upon completion. Key features include support for displaying milliseconds with configurable precision, an `overtime` prop to allow negative countdowns, and an API to programmatically `stop`, `isStarted`, and `isStopped` the countdown. It ships with TypeScript types, ensuring type safety for React applications. This package differentiates itself through its extensive customization capabilities and robust API for managing countdown state.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic countdown with a custom renderer and completion callback, using modern React 18+ ReactDOM.createRoot.

import React from 'react';
import ReactDOM from 'react-dom/client';
import Countdown from 'react-countdown';

// Create a root
const root = ReactDOM.createRoot(document.getElementById('root'));

const Completionist = () => <span>Time's up!</span>;

const renderer = ({ hours, minutes, seconds, completed }) => {
  if (completed) {
    return <Completionist />;
  } else {
    return <span>{hours}:{minutes}:{seconds}</span>;
  }
};

root.render(
  <React.StrictMode>
    <Countdown
      date={Date.now() + 10000} // Countdown for 10 seconds
      renderer={renderer}
      onComplete={() => console.log('Countdown finished!')}
    />
  </React.StrictMode>
);

view raw JSON →