relative time in redux reactjs

Viewed 955

I have some data with datetime fields , i want to show the relative date time using momentJS fromNow(). However after the initial load it shows timestamp as a few seconds ago. But this will not be updated until a next state change triggered. Is it a good practice to keep another state in the state-tree & control via a timer function setInterval in componentDidUpdate?

render()
{
   // get the new prop value here which triggered from a setInterval -> action -> reducer -> state change -> propagate to connected components
   const text = comment.get('text');
   const dateTime = moment(comment.get('dateTime')).fromNow();
   return (
     // add the new prop into the component
     <div key={id}>
        <Comment
         text = {text}
         dateTime = {dateTime}
     </div>
}
1 Answers
Related