client/src/components/Clock.js
author ymh <ymh.work@gmail.com>
Fri, 16 Nov 2018 11:19:13 +0100
changeset 173 0e6703cd0968
parent 170 7da1d5137b0b
permissions -rw-r--r--
Correct the Note editor. Split the source file in sub components. Correct a timing problem on the editor checkbox.

import React, { Component } from 'react';
import moment from 'moment';

class Clock extends Component {

  state = {
    time: moment().format('H:mm:ss'),
    intervalID: null
  }

  componentDidMount() {
    const intervalID = setInterval(() => {
      const time = moment().format('H:mm:ss');
      this.setState({ time });
    }, 1000);

    this.setState({ intervalID });
  }

  componentWillUnmount() {
    clearInterval(this.state.intervalID);
  }

  render() {
    return (
      <span className="text-warning bg-irinotes-headers">{ this.state.time }</span>
    );
  }
}

export default Clock