1 | import React from "react";
|
2 |
|
3 | import { addMonths, isSameMonth } from "date-fns";
|
4 | import { DayPicker } from "react-day-picker";
|
5 |
|
6 | export function Controlled() {
|
7 | const today = new Date();
|
8 | const nextMonth = addMonths(new Date(), 1);
|
9 | const [month, setMonth] = React.useState<Date>(nextMonth);
|
10 |
|
11 | return (
|
12 | <div>
|
13 | <DayPicker month={month} onMonthChange={setMonth} />
|
14 | <button
|
15 | style={{ all: "unset", cursor: "pointer", color: "blue" }}
|
16 | disabled={isSameMonth(today, month)}
|
17 | onClick={() => setMonth(today)}
|
18 | >
|
19 | Go to Today
|
20 | </button>
|
21 | </div>
|
22 | );
|
23 | }
|