title: React js - Clarification needed for timer
body: <p>I just saw the tutorial of creating a timer and tried it on my own but am not sure how they are able to subtract new Date() - Date.now() ; if i hardcode this , it gives me 0 .But if the Date.now() when passed as a prop it gets incremented . Can anyone please Explain ??</p>
  
  <p>This is my App.js file.</p>
  
  <pre><code>    import React, { Component } from 'react';
  import Timer from './Timer';
  import './App.css';
  
  class App extends Component {
  
  
  
    render() {
      return (
        &lt;div className='App'&gt;
  
          &lt;Timer start={Date.now()} /&gt;
  
        &lt;/div&gt;
      );
    }
  }
  
  export default App;
  </code></pre>
  
  <p>This is my Timer.js file </p>
  
  <pre><code>import React,{ Component } from 'react';
  
  class Timer extends Component {
  
  componentDidMount()
  {
    console.log("component is mounted");
    setInterval(this.timer,1000);
  }
  
  constructor(props){
    super(props);
  
    this.state = {clock:0};
    this.timer = this.timer.bind(this);
  }
  
  timer()
  {
    this.setState( {clock:new Date() - this.props.start} );
  
  }
  
    render(){
  
      var clock = Math.round(this.state.clock/1000);
      return(
        &lt;div&gt;
          &lt;p&gt; you are in this site for &lt;/p&gt;
          &lt;span &gt; {clock} &lt;/span&gt;
          &lt;br /&gt;
          &lt;p&gt; seconds &lt;/p&gt;
        &lt;/div&gt;
      );
    }
  }
  
  export default Timer ;
  </code></pre>