react-flatpickr is a React component that wraps the popular Flatpickr date and time picker library, providing a declarative way to integrate it into React applications. The current stable version is v4.0.11, with development showing consistent maintenance releases, primarily focusing on TypeScript support, module resolution fixes, and improving ref handling. Key differentiators include its lightweight nature (inheriting from Flatpickr), comprehensive prop-based configuration aligning with Flatpickr's extensive options and event hooks, and support for render props for highly customizable input elements. It ships with TypeScript types, making it well-suited for modern React projects using TypeScript. Unlike some heavier date pickers, it aims for simplicity and performance by leveraging Flatpickr's efficient core.
npm install react-flatpickrVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate react-flatpickr into a functional React component with state management, custom Flatpickr options, and how to access the underlying Flatpickr instance via a ref for advanced manipulations.
For direct instance access with `useRef`, ensure the ref type is `React.RefObject<Flatpickr>` for the component itself, or `DateTimePickerHandle` if using `useImperativeHandle` with a custom component. The `flatpickr` instance is available at `ref.current.flatpickr`.
Add an import statement for a Flatpickr theme CSS file, e.g., `import 'flatpickr/dist/themes/material_green.css';` in your main application or component file.
Update TypeScript definitions or custom component logic to align with `Ref` type usage if directly manipulating `react-flatpickr`'s internal ref structure.
Run `npm install flatpickr` or `yarn add flatpickr` in your project.
Update to `react-flatpickr` version `4.0.6` or higher to resolve known module resolution and default import errors.
Ensure you have `flatpickr` installed (`npm install flatpickr`) and import a theme stylesheet, e.g., `import 'flatpickr/dist/themes/material_green.css';`.
Use the correct ESM default import: `import Flatpickr from 'react-flatpickr';`.
Type your ref with `React.RefObject<Flatpickr>` (where `Flatpickr` is the imported component) or use `DateTimePickerHandle` if you're using `useImperativeHandle` for custom ref exposure, as shown in the quickstart example.
Verify that both `react-flatpickr` and `flatpickr` are correctly installed and that the import `import Flatpickr from 'react-flatpickr';` is resolving correctly.