Search code examples
reactjsdatepickerreact-datepicker

How to dynamically disable days in react datepicker


I am using React DatePicker .I want to disable days in date picker. I am able to doing so by passing day number like below so Monday Tuesday and Saturday get's disabled.But how do I achieve this dynamically? I am able to form array like this var notAvailableDays=[1,2,6] // which should disable these days. How do I return this at once?

const isWeekday = (date) => {
   const day = date.getDay(date);
   return day !== 1 && day !== 2 && day !== 6;
  }

;


Solution

  • You can do an array lookup like this

    const notAvailableDays = [1,2,6];
    
    const isDisabled = (date) => {
       const day = date.getDay(date);
       return notAvailableDays.includes(day);
    }