Skip to content

Instantly share code, notes, and snippets.

@noblesilence
Created July 19, 2018 10:46
Show Gist options
  • Save noblesilence/f27baef6beda6edf8a6569cbb925b8fd to your computer and use it in GitHub Desktop.
Save noblesilence/f27baef6beda6edf8a6569cbb925b8fd to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
import "./App.css";
import EasyTimer from "easytimer";
class App extends Component {
constructor() {
super();
this.state = { timer: null, timeValues: "" };
}
componentDidMount() {
let timer = new EasyTimer();
this.setState({ timer: timer });
timer.start();
timer.addEventListener("secondsUpdated", this.tick);
}
tick() {
const { timer } = this.state;
const timeValues = timer.getTimeValues().toString();
this.setState({ timeValues: timeValues });
console.log(`timer: ${timer}`);
}
render() {
return <div className="App">{this.state.timeValues}</div>;
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment