Created
August 8, 2018 18:05
-
-
Save Hypnosphi/b86afeb1baf04316096b49ad73a38956 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
class Example extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {date: new Date()}; | |
} | |
componentDidMount() { | |
this.timerID = setInterval( | |
() => this.tick(), | |
1000 | |
); | |
} | |
componentWillUnmount() { | |
clearInterval(this.timerID); | |
} | |
tick() { | |
this.setState({ | |
date: new Date() | |
}); | |
} | |
render() { | |
return ( | |
<div> | |
<h1>Hello, world!</h1> | |
<h2> | |
<SuperEllipsis tailLength={9}> | |
It is {this.state.date.toLocaleTimeString()}. | |
</SuperEllipsis> | |
</h2> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment