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-rangeVerified import paths — ran on the pinned version, not inferred.
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.
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`.
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`.
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.
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.
Ensure you are using `react-date-range` version `1.1.4` or higher to avoid these installation and dependency resolution problems.
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.
`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.
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())`.