Registry / web-framework / react-date-range

react-date-range

JSON →
library2.0.1jsnpmunverified

react-date-range is a React component library designed for selecting single dates or date ranges, offering a highly configurable and stateless approach to date management. As of version 2.0.1, it leverages `date-fns` for underlying date operations, requiring it as a peer dependency (minimum `date-fns` v2.0.0-alpha.1). It features multiple range selection, drag-and-drop capabilities, and keyboard navigation, using native JavaScript Date objects for all inputs and outputs. While previously actively maintained, the project's maintainers have stated it is currently unmaintained and will not be updated in the foreseeable future, making its release cadence effectively paused. Key differentiators include its flexibility, emphasis on native Date objects, and `date-fns` agnosticism (via peer dependency) over deprecated libraries like Moment.js.

npm install react-date-range
INSTALL
IMPORT
SIG · REACT-DATE-RANGE
R
react-date-range
web-frameworkjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Calendar
import { Calendar } from 'react-date-range';
const Calendar = require('react-date-range').Calendar;
Primarily used for single date selection. Ensure you import the named export.
DateRangePicker
import { DateRangePicker } from 'react-date-range';
import DateRangePicker from 'react-date-range/lib/DateRangePicker';
This is the primary component for selecting date ranges. Older versions might have different subpath imports, but named export from root is standard since v1.
DateRange
import { DateRange } from 'react-date-range';
require('react-date-range').DateRange;
Similar to DateRangePicker but for simplified range selection, often used internally or when finer control over range rendering is needed. Named export.
Styles
import 'react-date-range/dist/styles.css'; import 'react-date-range/dist/theme/default.css';
Essential CSS files must be imported to properly display the components. 'styles.css' provides the core layout, and a theme like 'default.css' provides visual styling.

This quickstart demonstrates how to set up a `DateRangePicker` component with initial state using React hooks, handling selection changes, and importing the necessary styles. It displays two months horizontally and logs the selected date range to the console.

import React, { useState } from 'react'; import { DateRangePicker } from 'react-date-range'; import 'react-date-range/dist/styles.css'; // main style file import 'react-date-range/dist/theme/default.css'; // theme css file function MyDateRangePicker() { const [state, setState] = useState([ { startDate: new Date(), endDate: null, key: 'selection' } ]); const handleSelect = (ranges) => { setState([ranges.selection]); console.log('Selected range:', ranges.selection); // You would typically update your application state here // e.g., send ranges.selection.startDate and ranges.selection.endDate to a parent component or API }; return ( <div> <h2 style={{ marginBottom: '15px' }}>Select a Date Range</h2> <DateRangePicker ranges={state} onChange={handleSelect} showSelectionPreview={true} moveRangeOnFirstSelection={false} months={2} // Display two months direction="horizontal" /> </div> ); } // To use this component in a React app, you'd typically render it: // import { createRoot } from 'react-dom/client'; // const container = document.getElementById('root'); // const root = createRoot(container); // root.render(<MyDateRangePicker />);
Debug
Known issues
breaking`date-fns` is now a peer dependency requiring version `>=2.0.0-alpha.1`. Using older `date-fns` versions (pre-v2) will cause issues, particularly with unicode tokens in `date-fns` format strings, unless specific compatibility props are passed.
fix
Upgrade `date-fns` to version `^2.0.0` or higher in your project. If an upgrade is not possible, refer to the `date-fns` v2 migration guide and `react-date-range` documentation for compatibility props like `dateDisplayFormat`.
affects: >=1.0.1
breaking`Calendar` and `DateRange` components became fully controlled, meaning they now require explicit `date` or `ranges` props and `onChange` handlers. Additionally, input and output values are strictly native `Date` objects, and `moment.js` is no longer used or bundled out-of-the-box.
fix
Refactor your components to pass `Date` objects for date props and handle changes via `onChange` callbacks. Remove any reliance on `moment.js` for date operations directly involving `react-date-range`.
affects: >=1.0.0-alpha0
gotchaThe project is officially unmaintained by its current owners, meaning no new features, bug fixes, or security patches are expected in the foreseeable future. This significantly increases the risk for long-term production use.
fix
Exercise caution when adopting for new projects. For existing projects, consider forking the repository to self-maintain or evaluate alternative actively maintained date picker libraries.
affects: >=2.0.0
gotchaThe project's license changed in 2020 and ownership was transferred to Hypeserver due to Adphorus being acquired. Review the updated license terms to ensure compliance for your use case.
fix
Consult the `LICENSE` file in the package repository or distribution for the most up-to-date licensing information and ensure it aligns with your organizational policies.
affects: >=1.1.4
gotchaVersions prior to `1.1.4` (specifically `1.1.3`) had known issues with installing third-party dependencies and handling `date-fns` as a peer dependency.
fix
Ensure you are using `react-date-range` version `1.1.4` or higher to avoid these installation and dependency resolution problems.
affects: <1.1.4
Errors
Common errors & fixes
TypeError: date_fns__WEBPACK_IMPORTED_MODULE_2__.format is not a function
Using `react-date-range` with a `date-fns` version older than 2.0.0 (e.g., v1.x) without providing specific format props compatible with the older `date-fns` API, after `react-date-range` adopted `date-fns` v2+ compatibility.
fix
Upgrade `date-fns` to version `^2.0.0` or higher in your project's `package.json`. If an upgrade is not feasible, explicitly provide `dateDisplayFormat` and other format-related props that are compatible with your specific `date-fns` v1.x version.
ReferenceError: moment is not defined
Your application code relies on `moment.js` being implicitly available or used internally by `react-date-range` after the `v1.0.0-alpha0` breaking change, which removed `moment.js` dependency.
fix
`react-date-range` no longer bundles or depends on `moment.js` since `v1.0.0-alpha0`. All date inputs and outputs are native `Date` objects. Refactor your code to use native `Date` objects or `date-fns` directly for date manipulations.
RangeError: Invalid time value
An invalid `Date` object (e.g., `new Date(null)`, `new Date('invalid-string')`, or a `null`/`undefined` value) is passed to a `date` or `ranges` prop of `Calendar` or `DateRangePicker`, causing `date-fns` to fail during date operations.
fix
Ensure all `Date` objects passed to `react-date-range` components are valid instances. Always validate date inputs from external sources before passing them to the component, for example, by checking `!isNaN(newDate.getTime())`.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
reactrequiredRequired as a peer dependency for all React component functionality.
date-fnsrequiredRequired as a peer dependency for all underlying date operations; allows projects to manage their own date-fns version. Requires >=2.0.0-alpha.1.
Agent activity
4 hits · last 30 days
node
4
Resources
react-date-range — npm install react-date-range · libregistry