React Dates

21.8.0 · maintenance · verified Tue Apr 21

React Dates is a robust and accessible date range picker component library for React, developed and maintained by Airbnb. It offers highly customizable single and range date pickers, including features like internationalization, mobile responsiveness, and full accessibility support. The current stable version is 21.8.0. The library relies on `moment` for all date handling, which is a significant architectural decision as `moment` is now in maintenance mode. Since v13.0.0, it mandates an explicit initialization import (`react-dates/initialize`) to set up its underlying `react-with-styles` styling solution, and it assumes `box-sizing: border-box` is globally applied for correct layout. Its release cadence has slowed, with the last npm publication over six years ago, suggesting it's in a maintenance phase rather than active feature development, though still widely used.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the basic setup and usage of the `DateRangePicker` component from `react-dates`. It includes the necessary global initialization and CSS imports, manages date state using React hooks, and shows a functional date range selection example. It also includes comments on important global CSS settings and common props for the picker.

import React, { useState } from 'react';
import 'react-dates/initialize';
import { DateRangePicker } from 'react-dates';
import 'react-dates/lib/css/_datepicker.css';
import moment from 'moment';

// IMPORTANT: Ensure global box-sizing: border-box for correct layout.
// Add this to your global CSS (e.g., index.css or App.css):
/*
html {
  box-sizing: border-box;
}
*,
*::before,
*::after {
  box-sizing: inherit;
}
*/

function MyDateRangePickerApp() {
  const [startDate, setStartDate] = useState(null);
  const [endDate, setEndDate] = useState(null);
  const [focusedInput, setFocusedInput] = useState(null);

  return (
    <div style={{ padding: '20px' }}>
      <h1>Book Your Stay</h1>
      <p>Select your desired check-in and check-out dates.</p>
      <DateRangePicker
        startDate={startDate} // momentPropTypes.momentObj or null
        startDateId="your_unique_start_date_id"
        endDate={endDate} // momentPropTypes.momentObj or null
        endDateId="your_unique_end_date_id"
        onDatesChange={({ startDate, endDate }) => {
          setStartDate(startDate);
          setEndDate(endDate);
        }}
        focusedInput={focusedInput} // PropTypes.oneOf([START_DATE, END_DATE]) or null
        onFocusChange={input => setFocusedInput(input)}
        orientation="horizontal"
        numberOfMonths={2}
        isOutsideRange={() => false} // Example: Allow all dates
        minimumNights={0}
        displayFormat="MM/DD/YYYY"
        hideKeyboardShortcutsPanel={true}
      />
      {startDate && endDate && (
        <p>
          Selected: {startDate.format('MM/DD/YYYY')} - {endDate.format('MM/DD/YYYY')}
        </p>
      )}
    </div>
  );
}

export default MyDateRangePickerApp;

view raw JSON →