Skip to content

Instantly share code, notes, and snippets.

@Peregg
Created April 24, 2018 07:50
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 Peregg/188015a382855f3eecf6737f7994bf28 to your computer and use it in GitHub Desktop.
Save Peregg/188015a382855f3eecf6737f7994bf28 to your computer and use it in GitHub Desktop.
Life Cycle Quest
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;
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