Skip to content

Instantly share code, notes, and snippets.

@basekays
Created June 20, 2018 22:18
Show Gist options
  • Select an option

  • Save basekays/d2c58502637d2d6878ae63a662b39ad4 to your computer and use it in GitHub Desktop.

Select an option

Save basekays/d2c58502637d2d6878ae63a662b39ad4 to your computer and use it in GitHub Desktop.
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {
date: new Date(),
}
}
comoponentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
);
}
tick() {
this.setState({
date: new Date(),
});
}
render() {
return (
<div>
<h3>Clock</h3>
<h3>It is now {this.state.date.toLocaleTimeString()}.</h3>
</div>
);
}
}
ReactDOM.render(
<Clock />,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment