Skip to content

Instantly share code, notes, and snippets.

@justinehell
Created August 10, 2020 13:10
Show Gist options
  • Save justinehell/a5d3423e520d308d6d21a5b1ad684034 to your computer and use it in GitHub Desktop.
Save justinehell/a5d3423e520d308d6d21a5b1ad684034 to your computer and use it in GitHub Desktop.
Cycle de vie - React
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