reactjsreact-datepicker

React Datepicker exclude past dates


I'm using this lib in my app:

https://reactdatepicker.com/

There is an excludeDates prop which I can use, where I can pass a list of dates aka this would exclude today and yesterday:

excludeDates={[moment(), moment().subtract(1, "days")]}

I would prefer to have a better way than passing however many hundreds of dates into that array though.

Thanks!


Solution

  • Maybe you can use the component like that:

    <DatePicker
      selected={this.state.startDate}
      onChange={this.handleChange}
      minDate={moment().toDate()}
      placeholderText="Select a day"
    />
    

    You can use minDate and maxDate props to select a unique range of date selectable.