JSFiddle - React, Tailwind, and code Playground
by ordette
HTML
<div id="root"></div>
React
class Clock extends React.Component {
constructor(props){
super(props);
this.state = {
clock: new Date()
}
}
componentDidMount(){
this.timerID = setInterval(()=> this.tick(), 1000);
}
componentWillUnmount(){
clearInterval(this.timerID);
}
tick(){
this.setState({ clock: new Date()});
}
render(){
return (
<div>{this.state.clock.toLocaleTimeString()}</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Clock/>);