Skip to content

Instantly share code, notes, and snippets.

@manoelneto
Created August 7, 2018 21:05
Show Gist options
  • Save manoelneto/aaa0cd0a4ef7bacad3ba42ff156440ed to your computer and use it in GitHub Desktop.
Save manoelneto/aaa0cd0a4ef7bacad3ba42ff156440ed to your computer and use it in GitHub Desktop.
import React, { Component, createElement } from 'react';
class CurrentTime extends Component {
state = {
time: new Date()
}
tick = () => {
this.setState({time: new Date()})
}
componentDidMount() {
this.interval = setInterval(this.tick, 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
const {
component
} = this.props;
return createElement(component, this.state);
}
}
export default CurrentTime;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment