React Datepicker is a comprehensive and highly customizable date picker component for React applications, currently stable at version 9.1.0. It receives frequent updates, with minor and patch releases often occurring monthly, addressing bugs, accessibility, and adding features, while major versions introduce significant enhancements like timezone support. Key differentiators include extensive configuration options for date and time selection, robust support for date ranges, year/month/quarter selection, and a strong focus on accessibility. It integrates seamlessly with `date-fns` for date manipulation and `date-fns-tz` for timezone handling, offering developers a flexible solution for various date input requirements in their projects. It ships with TypeScript types, facilitating safer and more predictable development.
npm install react-datepickerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic single date and date range selection, including CSS import and locale registration, within a functional React component.
Install `date-fns-tz`: `npm install date-fns-tz` or `yarn add date-fns-tz`. Ensure your date objects are handled correctly with `date-fns` utilities if manipulating them.
Upgrade to `react-datepicker@9.1.0` or higher to restore intended date parsing behavior. If sticking to older v8 versions, manually parse dates before passing them to the component or ensure formats are strictly compatible.
Upgrade to `react-datepicker@8.6.0` or higher for better compatibility with React 19.
Ensure `import 'react-datepicker/dist/react-datepicker.css';` is included in your application's entry point or a component where the datepicker is used. Verify your build system is configured to handle CSS imports.
Import the desired locale from `date-fns/locale` and register it using `registerLocale('my-locale-code', myLocale);` from `react-datepicker`.Change `import { DatePicker } from 'react-datepicker';` to `import DatePicker from 'react-datepicker';`.The correct path is `react-datepicker/dist/react-datepicker.css`. Update your import statement accordingly: `import 'react-datepicker/dist/react-datepicker.css';`
Ensure `date-fns` functions are imported correctly if you're using them, and that valid `Date` objects are passed to the `selected` prop and `onChange` handler. For localization, make sure `registerLocale` is used with a valid `date-fns` locale object.
Ensure that the `highlightDates` prop receives an array where each element is a `Date` object, e.g., `highlightDates={[new Date(), addDays(new Date(), 7)]}`.