I have a live clock working pretty good except in the morning hours, it displays 1:2:3
when it should display 01:02:03
How can I modify this to work in a ReactJS component? I'm very new at React and the ways to implement a javascript function are not quite the same so I can't really use any of the regular JS answer I find. Here is the code in my class:
class SidebarContent extends React.Component {
constructor(props) {
super(props);
this.state = {
date: new Date()
};
}
componentWillUnmount() {
clearInterval(this.timerID);
}
tick() {
this.setState({date: new Date()});
}
getHours() {
return this.state.date.getHours();
}
getMinutes() {
return this.state.date.getMinutes();
}
getSeconds() {
return this.state.date.getSeconds();
}
componentDidMount() {
this.timerID = setInterval(() => this.tick(), 1000);
}
render() {
return (
<ul className="nav" ref={(c) => {this.nav = c; }}>
<li className="today">
<Row className="clock" center="xs">
<Row center="xs">
<span className="hours">{this.getHours()}</span>
<span>:</span>
<span className="min">{this.getMinutes()}</span>
<span className="sec">{this.getSeconds()}</span>
</Row>
</Row>
<Row className="date" center="xs">
<p className="today-is">{this.state.date.toDateString()}</p>
</Row>
</li>
</ul>
);
}
}
Thanks in advance