Else if
Condition not give response on 1st click button, it always give response 2nd click on button. I'm trying get date diff between two date
, minimum date to maximum date.
Date came every click according to selected date, but maxDate & minDate not set in state.
After 2nd click first date set in minDate, 3rd click set 2nd date as maxDate. But i want set date as well as click on button.
this.onDayPress = this.selecionarData.bind(this);
selecionarData(date){
let {year, month, day} = date;
if (this.state.minDate && this.state.maxDate) {
if (this.state.minDate > day) {
this.setState({
minDate: day
});
} else {
this.setState({
maxDate: day
});
}
} else if (this.state.minDate && this.state.maxDate === undefined) {
if (this.state.minDate > day) {
this.setState({
minDate: day,
maxDate: this.state.minDate
});
} else {
this.setState({
maxDate: day
})
}
} else {
this.setState({
minDate: day
});
}
Make sure you set the initial state for minDate
and maxDate
.
See here for documentation: https://facebook.github.io/react/docs/react-component.html#setstate
Thank you so much to giving idea. Actually it's work link this in my case :
if (this.state.minDate > day) {
this.setState({
minDate: day
},() =>{this.methodCall()});
} else {
this.setState({
maxDate: day
},() =>{this.methodCall()});
}
}
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.