Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Where is timerID coming from?

I'm halfway to understanding how this.timerId doesn't cause an error in the react docs.

class Clock extends React.Component {
  constructor(props) {
    super(props);
    this.state = {date: new Date()};
  }

  componentDidMount() {
    this.timerID = setInterval(
      () => this.tick(),
      1000
    );
  }

  componentWillUnmount() {
    clearInterval(this.timerID);
  }

  tick() {    this.setState({      date: new Date()    });  }
  render() {
    return (
      <div>
        <h1>Hello, world!</h1>
        <h2>It is {this.state.date.toLocaleTimeString()}.</h2>
      </div>
    );
  }
}

ReactDOM.render(
  <Clock />,
  document.getElementById('root')
);

I get that timerId along with setInterval come from Node. I thought node was just the runtime, does it come with other modules aside from Node Timers? Where is timerID initialized and or inherited from? Do all objects get a timerID when running on Node?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

this.timerID in this case is created as a new property at the point that it is assigned a Value, as pointed out by @luk2302 in the comments.

Below shows another possible way you could refer to a property that wasn't created in that class directly, but in the parent class.

class SuperClass {
    constructor() {
        this.superProperty = "Hello I'm super!"
    }
}

class SupportClass extends SuperClass{
    constructor(example) {
        super();
        this.example = example;
    }

    supportMethod() {
        console.log(this.example);
        console.log(this.superProperty);
    }

}

let supportClass = new SupportClass("HELLO");

supportClass.supportMethod();

this produces an output:

HELLO
Hello I'm super!
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!