I'm using SingleDatePicker
from react-dates
and it works fine when selecting a date from the datepicker(even a past date), but when the user types a past date the onDateChange
handler returns null, but when the user types a future date onDateChange
returns a moment object.
<SingleDatePicker
date={moment(Date.now())}
focused={focused}
displayFormat="MM/DD/YYYY"
onFocusChange={() => setFocused(!focused)}
onDateChange={date => {
console.log(date);
}}
/>
Here's what i get when typing the current or future date and null
is when typing a past date.
If you want to select past days, pass in isOutsideRange={() => false}
prop.
<SingleDatePicker
date={moment(Date.now())}
focused={true}
displayFormat="MM/DD/YYYY"
onFocusChange={() => true}
onDateChange={date => {
console.log(date);
}}
isOutsideRange={() => false}
/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.