Skip to content

Instantly share code, notes, and snippets.

@MagicControl
Last active January 31, 2017 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MagicControl/7b11ef59b139844320675fe5392faa2c to your computer and use it in GitHub Desktop.
Save MagicControl/7b11ef59b139844320675fe5392faa2c to your computer and use it in GitHub Desktop.
simple react component
class TestComponent extends React.Component {
constructor() {
super();
this.state = {date: new Date()};
}
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
);
}
componentWillUnmount() {
clearInterval(this.timerID);
}
tick() {
this.setState({
date: new Date()
});
}
render() {
return (
<span>{this.state.date.toLocaleTimeString()}</span>
)
}
}
ReactDOM.render(
<TestComponent/>,
document.getElementById('app')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment