When using date range in one component instead of end date I get null
My component
const { startDate, endDate } = useSelector(selectFormData);
const [localDate, setLocalDate] = useState({
startDate: startDate,
endDate: endDate,
});
const onChange = (dates: [Date | null, Date | null], event: SyntheticEvent<any, Event> | undefined) => {
// const [startDate, endDate] = dates;
console.log(dates);
};
<DatePicker
id="single-datepicker"
selected={localDate.startDate}
onChange={onChange}
startDate={localDate.startDate}
endDate={localDate.endDate}
selectsRange
inline
minDate={new Date()}
monthsShown={2}
/>
but in dates i have array with date as startDate and null as endDate

I am facing the same issue. Please fix the bug asap.
Same here
Maybe, it is not a bug:
When there is a start date and end date selected and the user just click in a new date on the calendar, the behavior right now is to only delete the end date and set the date selected by the user as a new start date, so it just restart the selection of the date range
I am facing the same issue. Please fix the bug asap.
@Robertoleanonsystems is right. You can "fix" this like so:
onChange={ ([from, to]: [Date, Date]): void => {
if (!to) {
setFrom(from)
setTo(undefined)
}
else {
setFrom(from)
setTo(to)
}
} }
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.
If you only do console.log() in onChange, it doesn't work. You'll need to set the startDate into a React state, and reflect it into <DatePicker startDate={startDate} />. Then you'll be able to choose the endDate and get both values in return.
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.