0

I was trying to use singleDatePicer from react-dates,which is a popular date picker library by airbnb, on selecting a date, it throws the error date.format is not a function, and just breaks, my code sandbox link is -> https://08cg1.csb.app/. Thanks in Advance.

Aashiq
  • 447
  • 1
  • 12
  • 27

2 Answers2

1

singleDatePicker will accept moment object as date props so you need to change onDateChange like below:-

onDateChange={(date) => setDate(date)};
Priyank Kachhela
  • 2,517
  • 8
  • 16
1
onDateChange={(date) => {setDate(date);}}

Here, Don't change the date format and then set the state. Just set the state directly.

If you want to display that selected date somewhere else, there use the moment.

The issue was, once you changed the date format, that format is not supporting as value.