RangeError: Invalid time value on version 4.8.0
when using the dependency i get the error mentioned in the tittle on render, I looked through another issues and in stackedOverflow and saw that it was a problem with the format in versions lower than 2.3, however I'm currently using version 4.8.0 and formats described in the documentation,
`**import React, { useState } from "react"; import DatePicker from "react-datepicker";
export type DateSelectorType = { value?: Date, onChange: Function }
const DateSelector = ({ value = new Date(), onChange }: DateSelectorType) => { const [startDate, setStartDate] = useState(value); const [selectedDate, setSelectedDate] = useState(new Date()) const changeDates = (date: Date) => { setStartDate(date) setSelectedDate(date) onChange(date) } React.useEffect(() => { setStartDate(value) },[value]) return ( <div className="DateSelector"> <DatePicker dateFormat={"dd-mm-yy"} selected={startDate} onChange={(date: Date) => changeDates(date)} /> );** }; export default DateSelector`
How did you resolved this issue?
I'm also experiencing issues when providing custom date formats and using a customInput.
https://stackblitz.com/edit/react-ts-n6oswq?file=App.tsx
I was able to resolve this issue by parsing the date like in this comment but now any PM time I choose becomes an AM time.
Edit: If you use selected={new Date(value)} the time is correct. I still can't get AM/PM to show but I'm assuming that's a separate issue.
Update: The above suggestion does not work in Firefox or Safari.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.
I am still having this issue even on a non-range date picker. To solve this,
onChange={value => {
let dob = moment(value)
if (dob.isValid()) {
setDate(dob.toDate())
} else {
const date = new Date();
setDate(date)
}
}}
Same issue with Safari on iOS and MacOS
Hi Guys, i had the same issue, i solved it like this
<ReactDatePicker selected={(() => { if(passengerSeatInfo?.dob) { return new Date(passengerSeatInfo?.dob); }else { return passengerSeatInfo?.dob } })()} onChange={(e) => setPassengerInfo(prevData => ({...prevData, dob: e}))} />
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.
This issue was closed because it has been stalled for 10 days with no activity.