Last active
May 7, 2019 09:16
-
-
Save subeshb1/9ccea92b5fd190c45d7a8914bcbd05f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Timer extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
count: 0 | |
}; | |
} | |
componentDidMount() { | |
this.interval = setInterval(() => { | |
this.setState(({ count }) => ({ count: count + 1 })); | |
}, 1000); | |
} | |
componentWillUnmount() { | |
clearInterval(this.interval); | |
} | |
render() { | |
return ( | |
<div> | |
<h1>Count: {this.state.count}</h1> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment