React Calendar Component

6.0.1 · active · verified Tue Apr 21

React Calendar is a highly customizable and internationalization-friendly date picker component for React applications. Currently stable at version 6.0.1, it receives frequent updates that include new features, bug fixes, and performance improvements. It leverages modern React features like the new JSX transform and is distributed exclusively as an ES module since version 6.0.0. Key differentiators include its robust TypeScript support, extensibility through props like `tileClassName` and `tileContent`, and recent adoption of npm trusted publishing and immutable releases for enhanced supply chain security, aiming to improve overall supply chain security and reliability for users.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic interactive calendar with state management for date selection, supporting both single date and range selection.

import React, { useState } from 'react';
import Calendar from 'react-calendar';
import 'react-calendar/dist/Calendar.css';

type ValuePiece = Date | null;
type Value = ValuePiece | [ValuePiece, ValuePiece];

function MyCalendar() {
  const [value, onChange] = useState<Value>(new Date());

  return (
    <div className="my-calendar-container">
      <h1>Select a Date</h1>
      <Calendar onChange={onChange} value={value} />
      {value instanceof Date && value && (
        <p>Selected date: {value.toLocaleDateString()}</p>
      )}
      {Array.isArray(value) && value[0] instanceof Date && value[1] instanceof Date && (
        <p>Selected range: {value[0].toLocaleDateString()} - {value[1].toLocaleDateString()}</p>
      )}
    </div>
  );
}

export default MyCalendar;

view raw JSON →