Getting a RangeError: Invalid Time Value when using React datepicker

Just pass to your DatePicker component dateFormat="MM-DD-YYYY" prop, with your desired format.

https://reactdatepicker.com/#example-7

<DatePicker
  dateFormat="MM-DD-YYYY"
  selected={this.state.startDate}
  onChange={this.handleChange} 
/>

P.D. You would like to use useReducer instead of useState in the case your state is an object.


According to this post https://github.com/Hacker0x01/react-datepicker/issues/1752 you most probably use old version of datepicker, that also may not be fully consistent with your React environment.

So check your react-datepicker version, if needed upgrade to 2+, and use this syntax:

const selected = moment(isoDateStr).toDate();

This is because react-datepicker before version 2 uses moment object date type directly and version 2+ uses javascript date type instead.