Skip to content

Instantly share code, notes, and snippets.

@PradalCyril
Created November 12, 2018 13:58
Show Gist options
  • Save PradalCyril/c088b7daa2e0c510f1ada3bd658b600b to your computer and use it in GitHub Desktop.
Save PradalCyril/c088b7daa2e0c510f1ada3bd658b600b to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
class Timer extends Component {
constructor(props){
super(props);
this.state={valeur:0}
}
componentDidMount() {
const coucou = setInterval(() => {
console.log(this.state.valeur)
this.setState({valeur: this.state.valeur + 1})}, 1000)
}
componentWillUpdate() {
console.log('Un update a eu lieu');
}
componentWillUnmount() {
clearInterval(this.state.coucou);
}
render() {
return (
<div>
<h1>{this.state.valeur}</h1>
<button onClick={this.props.onExit}>Start</button>
</div>
);
}
}
export default Timer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment