import React from "react";

class Clock extends React.Component {
  constructor(props) {      //Constructor is  called when root is rendered
    this.state = { date: new Date() }; //intializes this.state with current time

  componentDidMount() { //React lifecycle method, is been called when clock output is inserted in the DOM
    this.timerID = setInterval(
        () => this.tick(),
    )           //Here class component asks the browser to set up a timer to call the tick() method once a second

    this.setState({         //calling setState method with an object containing the current time
        date: new Date()
    });                     //setState method updates the current time

  componentWillUnmount() {      // Incase if clock component is ever removed from the DOM , react call this lifecycle method so the timer is stopped.

  render() {
    return (
        <h1>Hello, world!</h1>
        <h2>It is {}.</h2>

export default Clock;