Created
April 23, 2018 14:27
-
-
Save soner8/e4e242b113d8dd456f27b98a28ecba9c to your computer and use it in GitHub Desktop.
timer
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
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