client/src/components/Clock.js
author ymh <ymh.work@gmail.com>
Fri, 28 Jul 2017 19:40:35 +0200
changeset 129 d48946d164c6
parent 28 abf9f3ff2635
child 143 cfcbf4bc66f1
permissions -rw-r--r--
Add a first version of synchronisation Remove redux-offline dependency make the redux state fully immutable TODO: better error management TODO: make syncronization work automatically

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