Skip to content

Instantly share code, notes, and snippets.

@prdxs
Last active April 20, 2021 11:46
Show Gist options
  • Save prdxs/ee0af23318e5e30e4b70dcaae78d4813 to your computer and use it in GitHub Desktop.
Save prdxs/ee0af23318e5e30e4b70dcaae78d4813 to your computer and use it in GitHub Desktop.
class Clock extends Component {
constructor(props) {
super(props);
this.state = {
time: new Date().toLocaleTimeString(),
};
}
componentDidMount() {
setInterval(() => {
this.setState({ time: new Date().toLocaleTimeString() });
}, 1000);
}
render() {
const { className, style } = this.props;
const { time } = this.state;
return (
<span
className={clsx('Clock', className)}
style={style}
>
{time}
</span>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment