1

I'm attempting to use SingleDatePicker to edit/add events in a database. I can create a new event outside of this calendar year, but when I go to edit any event past 2019, I am getting an 'invalid date' in my SingleDatePicker which crashes my site when clicked and gives the error "Uncaught TypeError: month must be a valid moment object" . I am using momentjs. It's worth noting that all dates are passed from my API in the exact same format, and I only have this issue with dates with years after 2019. When a date is after 2019 i get the error "Warning: Failed prop type: Invalid prop date of type object supplied to SingleDatePicker, expected Moment. " I am using moment though so i do not understand this error.

I've found no documentation of this issue.

`componentWillReceiveProps() {
if (this.props.date !== null) {
  let newDate = moment(this.props.date, "ddd, MMM DD yyyy HH:mm:ss 
Z");
  this.setState({ date: newDate });
}
....

....
....
....

<SingleDatePicker
                date={this.state.date} 
                isOutsideRange={() => false}
                onDateChange={date => this.setState({ date })} /
                focused={this.state.focused} 
                onFocusChange={({ focused }) => this.setState({ 
                focused })} 
                id="selectedDate" ,
              />`
kdamemphis
  • 11
  • 2

1 Answers1

0

I did a workaround that solved for me. When the date is null (like on our case) you can set it to today's date with moment like this:

onDateChange={date => this.setState({ date || moment().format('YYYY-MM-DD') })}