React Analog Clock

6.0.0 · active · verified Sun Apr 19

React-clock is a specialized React component library offering an analog clock display for web applications. It provides a highly configurable clock, allowing developers to set the current time, specify display precision down to milliseconds, and customize the appearance of hour marks and numbers. The library is currently stable at version 6.0.0 and actively maintained, with regular updates addressing bug fixes, performance enhancements, and compatibility with the latest React versions, including React 19. It ships with full TypeScript support, exporting its component props for robust type-checking. A key differentiator is its focus purely on an analog clock interface, providing a lightweight, purpose-built solution without the overhead of digital or calendar functionalities, offering a simple and elegant way to integrate time visualization into React applications. As of v6.0.0, it is an ESM-only package.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to render a basic analog clock that updates every second using React hooks.

import React, { useState, useEffect } from 'react';
import Clock from 'react-clock';
import 'react-clock/dist/Clock.css'; // Don't forget to import the CSS!

function MyAnalogClock() {
  const [value, setValue] = useState(new Date());

  useEffect(() => {
    const interval = setInterval(
      () => setValue(new Date()),
      1000
    );

    return () => {
      clearInterval(interval);
    };
  }, []);

  return (
    <div>
      <h1>Current Analog Time</h1>
      <Clock 
        value={value} 
        size={200} 
        renderNumbers={true} 
        hourMarksLength={10} 
        minuteMarksLength={5}
        className="my-custom-clock"
      />
      <p>This clock updates every second.</p>
    </div>
  );
}

export default MyAnalogClock;

view raw JSON →