onDateChange callback is made with old date value.
In datepicker.js "onDatePicked", the state is set with setState, then the callback occurs
immediately after, but the date value in setState isn't guaranteed to be set until next redraw so
the current value of state.date is sent in the callback.
Expected Behavior
correct new date value passed into the onDateChange callback
Code
onDatePicked({action, year, month, day}) {
this.setState({
date: new Date(year, month, day) // <= new state,date isn't guaranteed to be ready!!
});
this.datePicked(); // <= callback made here
// I kludge fix it by making my own datePicked function and passing in the new date to that
onDatePicked({action, year, month, day}) {
if (action !== DatePickerAndroid.dismissedAction) {
this.setState({
date: new Date(year, month, day)
});
// this.datePicked();
this.datePickedKludge( new Date(year, month, day) );
} else {
this.onPressCancel();
}
}
Issue
onDateChange callback is made with old date value. In datepicker.js "onDatePicked", the state is set with setState, then the callback occurs immediately after, but the date value in setState isn't guaranteed to be set until next redraw so the current value of state.date is sent in the callback.
Expected Behavior
correct new date value passed into the onDateChange callback
Code
Environment
react-native -v
: 16.8.3node -v
: v10.15.3npm -v
:yarn --version
:target platform
: Androidoperating system
: Win10