Skip to content

Commit

Permalink
use window for timers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohsen Azimi committed Jul 10, 2017
1 parent 838745a commit d1e7e91
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as React from "react";

export default class App extends React.Component<{}, { count: number; }> {
interval: NodeJS.Timer;
interval: number;
state = { count: 0 };

//This state will be maintained during hot reloads
componentWillMount() {
this.interval = setInterval(() => {
this.interval = window.setInterval(() => {
this.setState({ count: this.state.count + 1 })
}, 1000);
}

componentWillUnmount() {
clearInterval(this.interval);
window.clearInterval(this.interval);
}

render() {
Expand Down

0 comments on commit d1e7e91

Please sign in to comment.