React Date Picker Component

12.0.2 · active · verified Sun Apr 19

react-date-picker is a flexible date picker component for React applications, providing robust functionalities for selecting dates, months, and years. Its current stable version is 12.0.2. The package maintains an active release cadence, with minor and patch updates occurring frequently to address bugs and improve developer experience, while major versions are released less often, coinciding with significant architectural shifts or React version compatibility updates. Key differentiators include its lightweight nature, comprehensive TypeScript support, enhanced prop documentation via JSDoc for improved IDE assistance, and its transition to being an ESM-only package since v12.0.0, aligning with modern JavaScript module standards. It supports React versions 16.8.0 through 19.0.0 and mandates the New JSX Transform since v11.0.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart code demonstrates how to integrate `react-date-picker` into a React component, manage its state using `useState`, handle date changes, and correctly import required styles.

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

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

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

  return (
    <div>
      <h1>Date Selection Example</h1>
      <p>Select a date using the React Date Picker:</p>
      <DatePicker onChange={onChange} value={value} />
      {value && Array.isArray(value) ? (
        <p>Selected date range: {value[0]?.toDateString() || 'None'} - {value[1]?.toDateString() || 'None'}</p>
      ) : (
        <p>Selected date: {value?.toDateString() || 'None'}</p>
      )}
      <p>Current value in state: {JSON.stringify(value)}</p>
    </div>
  );
}

export default MyDatePickerComponent;

view raw JSON →