UNPKG

653 BTypeScriptView Raw
1import React, { useState } from "react";
2
3import { DayPicker, DayPickerProps } from "react-day-picker";
4
5export function CustomSingle() {
6 const [selectedDate, setSelectedDate] = useState<Date | undefined>();
7 const modifiers: DayPickerProps["modifiers"] = {};
8 if (selectedDate) {
9 modifiers.selected = selectedDate;
10 }
11 return (
12 <DayPicker
13 modifiers={modifiers}
14 onDayClick={(day, modifiers) => {
15 if (modifiers.selected) {
16 setSelectedDate(undefined);
17 } else {
18 setSelectedDate(day);
19 }
20 }}
21 footer={selectedDate && `You selected ${selectedDate.toDateString()}`}
22 />
23 );
24}