FAQ: Mounting Lifecycle Methods - componentDidMount

Compare your calls to this.setState()

// In componentDidMount()
this.setState({ date: new Date() });

// In componentDidUpdate()
this.setState({date: newDate()})
1 Like

I must have checked that line 10 times, but missed it.
Thank you.
Been learning SQL and got used to getDate…
Thanks again.

In step 4 of this exercise, the prompt reads:

" At the bottom of componentDidUpdate() , declare a new variable, called `delay."

Yet this is not present in the solution

componentDidUpdate(prevProps) {

    if (this.props.isPrecise === prevProps.isPrecise) {

      return;

    }

    clearInterval(this.intervalID);

    this.startInterval();

  }

Is this a typo?

The solution shown for the exercise is the final solution that we arrive at after completing all 5 steps. The solution doesn’t show partial/incremental solutions for each step.

There is no typo. In step 4, we do declare a new variable delay and implement the rest of the instructions laid out in step 4.
But, in step 5, we refactor our code and follow the instructions:

Create a new method, startInterval() , which will include all of the code for setting up the interval. Next, find the code that sets up the interval in componentDidUpdate() . (It should start with let delay and end with the call to setInterval() .) Cut and paste those into the body of startInterval() . In its place, put a call to this.startInterval() .

We remove the code from step 4 and place it in the startInterval() method.