client/src/components/Clock.js
author Alexandre Segura <mex.zktk@gmail.com>
Fri, 23 Jun 2017 11:16:34 +0200
changeset 80 b3a02ea6d097
parent 28 abf9f3ff2635
child 143 cfcbf4bc66f1
permissions -rw-r--r--
Implement note edition.

import React, { Component } from 'react';
import { Label } from 'react-bootstrap';
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 (
      <Label bsStyle="info">{ this.state.time }</Label>
    );
  }
}

export default Clock