Skip to content

Instantly share code, notes, and snippets.

@soner8
Created April 23, 2018 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soner8/e4e242b113d8dd456f27b98a28ecba9c to your computer and use it in GitHub Desktop.
Save soner8/e4e242b113d8dd456f27b98a28ecba9c to your computer and use it in GitHub Desktop.
timer
import React, {Component} from 'react';
class MyTimer extends React.Component {
constructor (props) {
super(props)
this.state = {count: 1}
}
componentDidMount () {
this.startTimer(this.timer)
}
tick () {
this.setState({count: (this.state.count + 1)})
console.log('un update a eu lieu')
}
startTimer () {
clearInterval(this.timer)
this.timer = setInterval(this.tick.bind(this), 1000)
}
render () {
return (
<div className='timer'>
<h1>{this.state.count}</h1>
<div>
</div>
</div>
)
}
}
export default MyTimer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment