Getting Started
Install the Package
DayPicker is available as react-day-picker
npm package. It requires date-fns as a peer dependency.
- npm
- Yarn
- pnpm
npm install react-day-picker date-fns
yarn add react-day-picker date-fns
pnpm add react-day-picker date-fns
- See #1087 if you are interested in DayPicker supporting different date libraries.
Basic Usage
To create a simple date picker calendar,
- Import the component and its default style from
react-day-picker
. - Choose a selection mode using the
mode
prop. - Assign the
selected
andonSelect
props to manage the selected date.
import { useState } from "react";
import { DayPicker } from "react-day-picker";
import "react-day-picker/dist/style.css";
export function MyDatePicker() {
const [selected, setSelected] = useState();
return <DayPicker mode="single" selected={selected} onSelect={setSelected} />;
}