Created
August 10, 2020 13:10
-
-
Save justinehell/a5d3423e520d308d6d21a5b1ad684034 to your computer and use it in GitHub Desktop.
Cycle de vie - React
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 from "react"; | |
class MyTimer extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
timer: 0, | |
}; | |
} | |
componentDidMount() { | |
console.log("le composant est monté"); | |
this.timerId = setInterval(() => this.tick(), 1000); | |
} | |
componentDidUpdate() { | |
console.log("un update a eu lieu"); | |
} | |
tick() { | |
this.setState({ | |
timer: this.state.timer + 1, | |
}); | |
} | |
render() { | |
return <div>My Timer : {this.state.timer}</div>; | |
} | |
} | |
export default MyTimer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment