Answer the question
In order to leave comments, you need to log in
How to use React-time-ago?
Good day to all!
Here I ran into a problem: I use React in an Angular application through ngReact. And here we need to use the following React Time Ago Component . But I can’t do anything with it ... He doesn’t have a Bower version ... Maybe someone will advise?
Answer the question
In order to leave comments, you need to log in
Here is My component example... Maybe it will be useful for someone.
moment - connected to the page and available in the scope.
props. date = a string in iso8601 date format is passed
, the default update occurs every 30 seconds
.factory('TimeAgo', [function () {
return React.createClass({
propTypes: {
date: React.PropTypes.string,
refreshMillis: React.PropTypes.number
},
getDefaultProps: function () {
return {
date: moment().format(),
refreshMillis: 30000
}
},
componentWillMount: function () {
this.intervals = [];
},
setInterval: function (fn, ms) {
this.intervals.push(setInterval(fn, ms));
},
componentWillUnmount: function () {
this.intervals.forEach(clearInterval);
},
componentDidMount: function () {
var interval = this.props.refreshMillis;
this.setInterval(this.forceUpdate.bind(this), interval);
},
render: function () {
return (<span>{moment(this.props.date).fromNow()}</span>);
}
});
}])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question