F4. Library of Languages/JavaScript (JS)
Reactjs - State the time of my pc
Ayin Kim
2023. 1. 10. 23:07
반응형
Abstract.
To utilise major feature in react.js, here is the example of composing the clock display.
const root = ReactDOM.createRoot(document.getElementById('root'));
class Clock extends React.Component {
render() {
return (
<div>
<h1>Hello, world!</h1>
<h2>It is {this.props.date.toLocaleTimeString()}.</h2>
</div>
);
}
}
function tick() {
root.render(<Clock date={new Date()} />);
}
setInterval(tick, 1000);
Source - codepen, Dan Abramov