daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import moment from 'moment';
  3.  
  4. class ChatItems extends Component {
  5.  
  6.   constructor(props){
  7.     super(props);
  8.     this.state = {date: moment(new Date(Date.now())).format()}
  9.   }
  10.  
  11.   componentWillMount() {
  12.     this.timerID = setInterval(
  13.       () => this.tick(),
  14.       1000
  15.     );
  16.   }
  17.  
  18.   tick() {
  19.     this.setState((prevState) => ({
  20.       date: moment(this.state.date).fromNow()
  21.     }));
  22.   }
  23.  
  24.   render() {
  25.     return (
  26.       <div>
  27.         <ul>
  28.           {this.props.listitems.map(item => (
  29.             <li key={item.id}>{this.state.date}: {item.text}</li>
  30.           ))}
  31.         </ul>
  32.       </div>
  33.     );
  34.   }
  35. }
  36.  
  37. export default ChatItems;
RAW Paste Data
Top