2017-10-10 7 views
0

J'essaie de mettre à jour le texte dans la balise div chaque fois que startDate et endDate obtiennent une nouvelle valeur mais div montre les anciennes valeurs. Comment puis-je mettre à jour le texte div avec changement d'étatRéagissez comment changer le texte div sur le changement d'état

import moment from 'moment'; 
import DatetimeRangePicker from 'react-bootstrap-datetimerangepicker'; 
class TestPage extends Component { 
constructor(props) { 
super(props); 
this.state = { 
startDate: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm'), 
endDate: moment().format('YYYY-MM-DD HH:mm'), 
}; 
} 

handleChange(event, payload) { 
this.setState({ 
startDate: payload.startDate.format('YYYY-MM-DD HH:mm'), 
endDate: payload.endDate.format('YYYY-MM-DD HH:mm') 
}); 
this.onChange(); 
this.props.sendDateRanges(payload); 
} 

onChange() { 
return `${this.state.startDate} - ${this.state.endDate}`; 
}); 
} 
render() { 
return (<div> 
<DatetimeRangePicker 
timePicker 
showDropdowns 
onShow={this.handleChange.bind(this)} 
onApply={this.handleChange.bind(this)} 
> 
</DatetimeRangePicker> 
<div>{onChange()}</div> </div>); 
} 
export default connect(mapStateToProps, actions)(TestPage); 

Répondre

0

Supprimer votre fonction onChange et faire ce lieu ...

render() { 
const dateDiff = `${this.state.startDate} - ${this.state.endDate}`; 
return (<div> 
<DatetimeRangePicker 
timePicker 
showDropdowns 
onShow={this.handleChange.bind(this)} 
onApply={this.handleChange.bind(this)} 
> 
</DatetimeRangePicker> 
<div>{dateDiff}</div> </div>); 
+0

cela a fonctionné grâce – NSh