Search code examples
javascriptreactjsmomentjsreact-dates

How to disable multiple date in react-dates with moment range


How can I block dates in react-dates airbnb with moment date range?

const BAD_DATES = [
   moment.range('2018-04-15', 'YYYY-MM-DD', '2018-04-27', 'YYYY-MM-DD'),
   moment.range('2018-05-10', 'YYYY-MM-DD', '2018-05-20', 'YYYY-MM-DD'),
];
const isDayBlocked = day => BAD_DATES.filter(d => d.isSame(day, 'day')).length > 0;
return (
  <DateRangePicker
    isDayBlocked={isDayBlocked}
    ...
  />
);

Solution

  • I have not used this component but I think you should like this.

    if it passing the selected day to the function -> You should use range.contains(day) in the filter

    OR

    if you passing the selected date range to the function -> you should use range1.overlaps(range2) in the filter