Skip to content

Instantly share code, notes, and snippets.

@hungdev
Last active August 6, 2019 10:37
Show Gist options
  • Select an option

  • Save hungdev/f712ca5f74d89ee9d4705bdaa7c9e484 to your computer and use it in GitHub Desktop.

Select an option

Save hungdev/f712ca5f74d89ee9d4705bdaa7c9e484 to your computer and use it in GitHub Desktop.
stop watch
import React, { Component } from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import './style.css';
import Stopwatch from 'react-stopwatch'
import moment from 'moment'
import TimerMixin from 'react-timer-mixin';

class App extends Component {
  constructor() {
    super();
    this.state = {
      name: 'React',
      counter: 0
    };
  }

  componentDidMount() {
// this.start()
       this.interval = setInterval(() => {
        // let time = moment().year(2018).month(10-1).date(17).hour(23).minute(59).second(this.state.counter ++).format('YYYY-MM-DD HH : mm : ss')
        let time = moment().hour(12).minute(32).second(this.state.counter).format('YYYY-MM-DD HH : mm : ss')
        this.setState({counter: this.state.counter + 1, time})
        }, 1000);
        // this.setState({time: time})
  }

  // getTime () {
  //   var counter = 0
  //   let time = moment().hour(3).minute(59).second(counter++).format('HH : mm : ss')
  //   this.setState({time})
  // }

  // start () {
  //   setInterval(this.getTime(), 1000)
  // }

  componentWillUnmount() {
//        clearInterval(this.getTime());
clearInterval(this.interval);
    }
  render() {
    return (
      <div>
        <Hello name={this.state.name} />
        <p>
          Start editing to see some magic happen :)
        </p>
        <div>ahhh: {this.state.time}</div>
      </div>
    );
  }
}

render(<App />, document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment