Search code examples
javascriptreactjsreact-day-picker

Prevent selection of same dates react-day-picker


I'm using react-day-picker and I when startDate is selected I want to prevent selection of same date. how is that possible? I tried incrementing startDate by 1 and set It as disabledDays before property but It messed up selection. so which is proper way to achieve this?

 disabledDays = {
      before: startDate,
    };

Solution

  • Maybe there is an easier way, but I achieved this using this:

    handleDayClick(day) {
        if (this.state.from && DateUtils.isSameDay(day, this.state.from)) return;
        const range = DateUtils.addDayToRange(day, this.state);
        this.setState(range);
      }