Created
October 27, 2020 15:14
-
-
Save Karnak19/1c5494c65eccc48939efd461fbcbb1a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { 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