Last active
February 9, 2019 23:57
-
-
Save nadeesha/a18b35a7b5e7df65426de9b40e4e0faf to your computer and use it in GitHub Desktop.
This file contains hidden or 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 LiveDate extends React.Component { | |
componentDidMount() { | |
// update state every second with | |
// the current time | |
setInterval(() => { | |
this.setState({ | |
liveDate: new Date().toISOString(), | |
}); | |
}, 1000); | |
} | |
render () { | |
return this.props.children({ | |
date: this.state.liveDate || "loading..." | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment