Created
November 12, 2018 13:58
-
-
Save PradalCyril/c088b7daa2e0c510f1ada3bd658b600b to your computer and use it in GitHub Desktop.
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={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