Search code examples
javascriptreactjsdatereact-dates

date.format is not a function reacr-dates


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.


Solution

  • 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.