Skip to content

Instantly share code, notes, and snippets.

@Karnak19
Created October 27, 2020 15:14
Show Gist options
  • Save Karnak19/1c5494c65eccc48939efd461fbcbb1a2 to your computer and use it in GitHub Desktop.
Save Karnak19/1c5494c65eccc48939efd461fbcbb1a2 to your computer and use it in GitHub Desktop.
import { Component } from 'react';
class Logger extends Component {
constructor(props) {
super(props);
this.state = {
date: new Date(),
};
}
componentDidMount() {
setInterval(() => {
this.setState({ date: new Date() });
}, 1000);
}
componentDidUpdate() {
console.log('New changes');
}
componentWillUnmount() {
clearInterval();
}
render() {
const { date } = this.state;
return (
<div>
<p>{date.toLocaleTimeString()}</p>
</div>
);
}
}
export default Logger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment