Open RBrNx opened 5 years ago
I ran into this issue as well. I believe it has to do with the fact that the format prop of datepicker mutates the date. The onDateChange
then receives a string date that is not parsable.
It would be nice if the format just displayed it in whatever format I wanted but didn't actually change the underlying date. That way when onDateChange
is fired, the date is still in a consumable format.
I can suggest to use ISO format of result date. I fixed my issues this way:
const format = "hh:MMM, DD MMMM, hh:mma" // crazy format
class DefaultTimePicker extends React.PureComponent {
render() {
const { selectedValue } = this.props
let value = null
if(selectedValue) value = moment(selectedValue).format(format)
return (
<DatePicker
date={value}
format={format}
onDateChange={this.handleChange}
/>
)
}
handleChange = value => {
const isoValue = moment(value, format).toISOString()
this.props.onValueChange(isoValue)
}
}
Issue
When using the DatePicker (even the example shown on the Github page) a warning is issue by Moment.js Deprecation warning: value provided is not in a recognized RFC2822 or ISO format.
The warning can be seen in the moment.js docs here: http://momentjs.com/guides/#/warnings/js-date/
Expected Behavior
No warnings should appear when using the component
Environment
react-native -v
: ^0.57.8node -v
: 10.14.2npm -v
: 6.4.1target platform
: Android | iOSoperating system
: Windows