Created
April 24, 2018 07:50
-
-
Save Peregg/188015a382855f3eecf6737f7994bf28 to your computer and use it in GitHub Desktop.
Life Cycle Quest
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 Timer extends Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
count: 0 | |
} | |
} | |
setTimer () { | |
this.setState({count : this.state.count + 1}) | |
if (this.state.count >= 20) { | |
alert('Boom ! Bitch !') | |
this.state.count = 0; | |
} | |
} | |
componentDidMount() { | |
setInterval(this.setTimer.bind(this), 1000); | |
} | |
componentWillUpdate() { | |
console.log('Le composant va se mettre à jour'); | |
} | |
render() { | |
return ( | |
<div> | |
<img src="https://wildcodeschool.fr/wp-content/uploads/2017/01/logo_orange_pastille.png" alt="wild" /> | |
<p>Attention ! Ca va péter dans {this.state.count}...</p> | |
</div> | |
); | |
} | |
} | |
export default 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 Timer extends Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
count: 0 | |
} | |
} | |
setTimer () { | |
this.setState({count : this.state.count + 1}) | |
if (this.state.count >= 20) { | |
alert('Boom ! Bitch !') | |
this.state.count = 0; | |
} | |
} | |
componentDidMount() { | |
setInterval(this.setTimer.bind(this), 1000); | |
} | |
componentWillUpdate() { | |
console.log('Le composant va se mettre à jour'); | |
} | |
render() { | |
return ( | |
<div> | |
<img src="https://wildcodeschool.fr/wp-content/uploads/2017/01/logo_orange_pastille.png" alt="wild" /> | |
<p>Attention ! Ca va péter dans {this.state.count}...</p> | |
</div> | |
); | |
} | |
} | |
export default Timer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment