[SOLVED] How to disable certain dates in reactdatepicker based on a json array?

Issue

This Content is from Stack Overflow. Question asked by Ethan

I have an API endpoint that returns a JSON response of invalid dates that should be disabled in the react date picker.For example i got the response from api as [‘2022-09-27’, ‘2022-09-26’, ‘2022-09-29’, ‘2022-09-28’, ‘2022-10-01’, ‘2022-10-02’, ‘2022-10-03’]



Solution

You can use ExcludeDate props in react-date picker..

 <DatePicker
      selected={startDate}
      onChange={onChange}
      startDate={startDate}
      endDate={endDate}
      // exclude the listed dates 
      excludeDates={[newDate('2022-09-27')]}
    />


This Question was asked in StackOverflow by Ethan and Answered by sms It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?