관리 메뉴

Silver Library (Archived)

Reactjs - State the time of my pc 본문

F4. Library of Languages/JavaScript (JS)

Reactjs - State the time of my pc

Chesed 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

'F4. Library of Languages > JavaScript (JS)' 카테고리의 다른 글

How to use 'this' keyword in JS?  (0) 2023.01.04