React Datepicker exclude past dates

penguinsource picture penguinsource · May 31, 2018 · Viewed 17.5k times · Source

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!

Answer

benjamin Rampon picture benjamin Rampon · May 31, 2018

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.