Minimum & Maximum Date
There are many cases where you want to somehow limit the user to choose a day in a appropriate range. That's when minimumDate
and mximumDate
props come in handy. Here are some examples:
Limiting from Today
import React, { useState } from "react";
import "react-modern-calendar-datepicker/lib/DatePicker.css";
import { Calendar, utils } from "react-modern-calendar-datepicker";
const App = () => {
const [selectedDay, setSelectedDay] = useState(null);
return (
<Calendar
value={selectedDay}
onChange={setSelectedDay}
minimumDate={utils().getToday()}
shouldHighlightWeekends
/>
);
};
export default App;
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Specifying Both Minimum and Maximum
import React, { useState } from "react";
import "react-modern-calendar-datepicke/lib/DatePicker.css";
import { Calendar } from "react-modern-calendar-datepicke";
const App = () => {
const defaultValue = {
year: 2019,
month: 4,
day: 15
};
const minimumDate = {
year: 2019,
month: 4,
day: 10
};
const maximumDate = {
year: 2019,
month: 4,
day: 21
}
const [selectedDay, setSelectedDay] = useState(
defaultValue
);
return (
<Calendar
value={selectedDay}
onChange={setSelectedDay}
minimumDate={minimumDate}
maximumDate={maximumDate}
shouldHighlightWeekends
/>
);
};
export default App;
SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30