If you want to disable only date range then you can use excludeDateIntervals
props.
But if you want to disable time also then check this.
Firstly, make an array of the slots which you want to be disabled like this.
let slots = [
{ start: new Date(2022, 8, 8, 13), end: new Date(2022, 8, 8, 14) },
{ start: new Date(2022, 8, 8, 15), end: new Date(2022, 8, 8, 17) },
{ start: new Date(2022, 7, 18, 12), end: new Date(2022, 7, 18, 18) },
{ start: new Date(2022, 8, 1, 9), end: new Date(2022, 8, 2, 13) },
]
You can define a object in any proper format or using Date function like this
// { start: "08/09/2022 13:00", end: "08/09/2022 14:00" }
// OR
// { start: new Date(2022, 8, 8, 3), end: new Date(2022, 8, 8, 5) }
Now use filterTime
prop of react-datepicker
filterTime={(time) => {
for (let i = 0; i < slots.length; i++) {
const e = slots[i];
var x = moment(time),
beforeTime = moment(e.start),
afterTime = moment(e.end);
if (
x.isBetween(beforeTime, afterTime) ||
x.isSame(moment(beforeTime)) ||
x.isSame(moment(afterTime))
) {
return false;
}
if (i + 1 == slots.length) {
return true;
}
}
}}