I am trying to figure out how to use setInterval or the like in Meteor with React for a timer. I have a child component that has an hour start and end time, and uses moment.js to get the current time. If the current time is between the start and end time, I show a progress bar.
I am using react-timer-mixin and now my component is as follows.
Driver = React.createClass({
mixins: [TimerMixin],
componentDidMount: function(){
this.setInterval(this.currentTime, 15000);
},
currentTime: function() {
var beginTime = moment(this.props.driver.startTime,"hh:mm");
var endTime = moment(beginTime).add(1,'hours');
var now = moment();
totalMin = endTime.diff(beginTime);
currMin = now.diff(beginTime);
if (moment(now).isBetween(beginTime, endTime)) {
progress = Math.round((currMin / totalMin) * 60, -1);
console.log(progress);
return progress;
}
else {
return 60
}
},
render() {
return (
<DriverBar current={this.currentTime()} total="60" />
);
}
});
, currentTime setInterval, 15 , . . , setInterval. <DriverBar />?
, , , .