Skip to content

Instantly share code, notes, and snippets.

@Hypnosphi
Created August 8, 2018 18:05
Show Gist options
  • Save Hypnosphi/b86afeb1baf04316096b49ad73a38956 to your computer and use it in GitHub Desktop.
Save Hypnosphi/b86afeb1baf04316096b49ad73a38956 to your computer and use it in GitHub Desktop.
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